# `Semver`
[🔗](https://gitlab.com/jaybarra/semver_mgr/blob/main/lib/semver.ex#L1)

Semver provides utilities to increment major, minor, or patch versions according to
Semantic Versioning (SemVer) rules, and to read/write versions from/to `mix.exs`.

## Usage

    mix semver

    mix semver.increment [options]

## Examples

    mix semver.increment patch
    mix semver.increment major 2

# `semver_field`

```elixir
@type semver_field() :: :major | :minor | :patch
```

# `increment`

Increments a specific field of a semantic version.

By default, incrementing a field resets all lower-priority fields to 0.
For example, incrementing `:minor` resets `:patch` to 0.

## Options

  * `:preserve` - A list of fields to keep their current values instead of resetting to 0.
    Example: `[preserve: [:patch]]` keeps the patch number when incrementing minor.

## Examples

    iex> Semver.increment(%Version{major: 1, minor: 0, patch: 0}, :patch)
    %Version{major: 1, minor: 0, patch: 1}

    iex> Semver.increment(%Version{major: 1, minor: 0, patch: 9}, :minor)
    %Version{major: 1, minor: 1, patch: 0}

    iex> Semver.increment(%Version{major: 1, minor: 0, patch: 9}, :minor, 1, preserve: [:patch])
    %Version{major: 1, minor: 1, patch: 9}

# `read_version`

```elixir
@spec read_version(Path.t()) :: Version.t()
```

Reads a `mix.exs` file and returns the parsed `%Version{}`.

# `write_version`

```elixir
@spec write_version(Path.t(), Version.t()) :: :ok
```

Writes a `%Version{}` into a `mix.exs` file in-place.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
