PHPackages                             phlak/semver-cli - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [CLI &amp; Console](/categories/cli)
4. /
5. phlak/semver-cli

ActiveCli[CLI &amp; Console](/categories/cli)

phlak/semver-cli
================

CLI tool for managing semantic versioning within a project

2.0.0(2y ago)64.1k↑200%1[1 PRs](https://github.com/PHLAK/SemVer-CLI/pulls)1MITPHPPHP ^8.1 || ^8.2 || ^8.3

Since Aug 19Pushed 2y ago1 watchersCompare

[ Source](https://github.com/PHLAK/SemVer-CLI)[ Packagist](https://packagist.org/packages/phlak/semver-cli)[ GitHub Sponsors](https://github.com/sponsors/PHLAK)[ Fund](https://paypal.me/ChrisKankiewicz)[ RSS](/packages/phlak-semver-cli/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (2)Dependencies (10)Versions (13)Used By (1)

 [![SemVer CLI](semver-cli.svg)](semver-cli.svg)

 [![Join our Community](https://camo.githubusercontent.com/073a08ec4c3c801a8e24c53184d95a6562d74582854cb46320bcd76ef48ea543/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4a6f696e5f7468652d436f6d6d756e6974792d3762313666662e7376673f7374796c653d666f722d7468652d6261646765)](https://github.com/PHLAK/SemVer-CLI/discussions) [![Become a Sponsor](https://camo.githubusercontent.com/00da07edf5fbff7528a4743d85563603f9284f02680e0ab1e73652e680878548/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4265636f6d655f612d53706f6e736f722d6363343139352e7376673f7374796c653d666f722d7468652d6261646765)](https://github.com/users/PHLAK/sponsorship) [![One-time Donation](https://camo.githubusercontent.com/e9b5aa71ffdb17943c10c6d6b4a3132b66a938495331e488ecbdad1f3c078879/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4d616b655f612d446f6e6174696f6e2d3030366262362e7376673f7374796c653d666f722d7468652d6261646765)](https://paypal.me/ChrisKankiewicz)
 [![Latest Stable Version](https://camo.githubusercontent.com/57621341d2f6624a704a7e96318cb9b1c16b63611702900edd9b071f3f20caed/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f50484c414b2f53656d5665722d434c492e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/PHLAK/SemVer-CLI) [![Total Downloads](https://camo.githubusercontent.com/7a008f8ce338fc20c2e7edcf25f829109064656123d351bf40d83e3cd6f6e616/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f50484c414b2f53656d5665722d434c492e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/PHLAK/SemVer-CLI) [![License](https://camo.githubusercontent.com/b56270b576b813fbdb2f9e949a818dc32972c6eb116d41ba8e0c03bd6e963136/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f50484c414b2f53656d5665722d434c492e7376673f7374796c653d666c61742d737175617265)](https://github.com/PHLAK/SemVer-CLI/blob/master/LICENSE) [![Build Status](https://camo.githubusercontent.com/49cb4ec402c77062c021663ac1e8f496194c10ef4bcf667d251c2462201e7c99/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f636f6d2f50484c414b2f53656d5665722d434c492e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.com/PHLAK/SemVer-CLI) [![StyleCI](https://camo.githubusercontent.com/2118b2e2a657ad741feb2cbb008900f82d9eb8fd17bd4b646e4dc773f3a5a895/68747470733a2f2f7374796c6563692e696f2f7265706f732f36313936303033302f736869656c643f6272616e63683d6d6173746572267374796c653d666c61742d737175617265)](https://styleci.io/repos/61960030)

 Command line tool for managing [semantic versioning](http://semver.org) for a project
 Created by [Chris Kankiewicz](https://www.ChrisKankiewicz.com) ([@PHLAK](https://twitter.com/PHLAK))

---

Requirements
------------

[](#requirements)

- [PHP](https://php.net) &gt;= 7.2

Installation
------------

[](#installation)

The SemVer CLI can be installed via [Composer](https://getcomposer.org)per-project or globally.

#### Per-project

[](#per-project)

```
composer require phlak/semver-cli

```

When installed to a projcet the `semver` tool is installed to the project's `vendor/bin` directory.

> ℹ️ It is recommended to add `vendor/bin` to your `PATH` environment variable when installing within a project. Otherwise you will have to call the command with a relative path (i.e. `vendor/bin/semver [arguments]`) every time.

#### Globally

[](#globally)

```
composer global require phlak/semver-cli

```

When required globally the `semver` tool will be installed to the global `${COMOPSER_HOME}/vendor/bin` directory.

> ℹ️ You should add `${COMOPSER_HOME}/vendor/bin` to your `PATH` environment variable when installing globally. If you don't you will have to specify the full installation path with every call call.

Usage
-----

[](#usage)

#### Initialization

[](#initialization)

To begin, you must initialize semantic versioning within a directory.

```
$ semver initialize

```

This initializes the version to `0.1.0` by creating a `VERSION` file containing the version in the current directory.

#### Initialize a Specific Version

[](#initialize-a-specific-version)

To initialize to a specific version, pass the version as an argument to the `initialize` command.

```
$ semver initialize 1.3.37

```

#### Initializing Incomplete Versions

[](#initializing-incomplete-versions)

Sometimes you may need to initialize semantic versioning with an incomplete version. By default the `initialize` command requires a valid semantic version string. If you want to allow the command to make a "best guess" attempt you can do so with the `--parse` option.

```
$ semver initialize --parse 1.2

```

#### Setting Version Values

[](#setting-version-values)

After initialization you can set (override) the complete version with the `set:version` command.

```
$ semver set:version 1.3.37

```

Alternately, you may set individual values.

```
$ semver set:major 1
$ semver set:minor 3
$ semver set:patch 37
$ semver set:pre-release beta.5
$ semver set:build 007

```

> ℹ️ Setting certain values may affect other values
>
> - Setting the `major` value will reset the `minor` and `patch` values to `0`.
> - Setting the `minor` value will only reset the `patch` value to `0`
> - Setting the the `major`, `minor` or `patch` value will also clear the `pre-release` and `build` values

#### Clearing Values

[](#clearing-values)

You may clear the `pre-release` or `build` values with the `clear` commands.

```
$ semver clear:build
$ semver clear:pre-release

```

#### Retrieving Values

[](#retrieving-values)

At any point after initialization you may get the full version.

```
$ semver get:version

```

To get the version prefixed with `v` (i.e. `v1.3.37`) use the `--prefix` option.

```
$ semver get:version --prefix

```

You may also retrieve individual values.

```
$ semver get:major
$ semver get:minor
$ semver get:patch
$ semver get:pre-release
$ semver get:build

```

If the `pre-release` and `build` values are unset they will return no output by default. To force output add the `--verbose` option.

```
$ semver get:pre-release --verbose
$ semver get:build --verbose

```

#### Incrementing the Version

[](#incrementing-the-version)

You can increment the version values with the `increment` command.

```
$ semver increment:major
$ semver increment:minor
$ semver increment:patch

```

> ℹ️ Incrementing certain values may affect other values
>
> - Incrementing the `major` value will reset the `minor` and `patch` values to `0`
> - Incrementing the `minor` value will only reset the `patch` value to `0`
> - Incrementing the `major`, `minor` or `patch` value will also clear the `pre-release` and `build` values

Adapters
--------

[](#adapters)

The method used for storing version information can be configured with the `--adapter` option. The following are the available adapters to choose from.

 `file` Stores the version in a regular file in the current directory (default) `composer`  Stores the version in the `composer.json` file under the [version](https://getcomposer.org/doc/04-schema.md#version) property When using the `file` adapter you can control the file to which commands read and write the version via the `--file` option. This option takes the name you'd like to use and will look for a file with that name in the current directory.

```
$ semver --file .version get:version

```

By default the `composer` adapter will look for your `composer.json` file in the current directory. If your `composer.json` file lives elsewhere you can specify the path with the `--composer` option.

```
$ semver --composer path/to/composer.json increment:major

```

> ℹ️ Adapter options can be passed passed along with any command.

Configuration
-------------

[](#configuration)

Instead of passing adapter options with every command you can set these options in a persistent configuration file. To enable the config create a file in your project directory with a name of `semver.config.php`. This file MUST be a PHP file and return an array with with one or more of the followng configuration options.

 `adapter` The storage adapter in which version data will be stored.

Equivilent to the `--adapter` option.

  `file_name` Name of the version file when using the file adapter.

Equvilent to the `--file` option.

  `composer_file` Path to the composer file when using the composer adpater

Equvilent to the `--composer` option.

 ### Examples

[](#examples)

```
