Simple CLI tool to check a semver version against a condition
There were many times I needed a way to check version numbers of programs in bash scrips. Conclusion: there is no way to do this right!
That is why I have created this little CLI tool to help me (and maybe you) out!
Just download a binary release on the GitHub Releases page.
If you would like to build it yourself, go ahead, the source code is in this repository.
semver [-q] <version> <condition>
A <condition>
specifies which versions are satisfactory, while <version>
specifies the version that needs to be checked against.
Adding -q
causes to the program to not give any output at all.
The command gives feedback using exit codes:
- 0: Version is valid for the given condition
- 1: Version is NOT valid for the given condition
- 128: Incorrect arguments/parameters.
A <condition>
is composed of an operator and a version.
The supported operators are:
<1.0.0
Less than1.0.0
<=1.0.0
Less than or equal to1.0.0
>1.0.0
Greater than1.0.0
>=1.0.0
Greater than or equal to1.0.0
1.0.0
,=1.0.0
,==1.0.0
Equal to1.0.0
!1.0.0
,!=1.0.0
Not equal to1.0.0
. Excludes version1.0.0
.
Note that spaces between the operator and the version will be gracefully tolerated.
A <condition>
can link multiple conditions separated by space:
Conditions can be linked by logical AND:
>1.0.0 <2.0.0
would match between both ranges, so1.1.1
and1.8.7
but not1.0.0
or2.0.0
>1.0.0 <3.0.0 !2.0.3-beta.2
would match every version between1.0.0
and3.0.0
except2.0.3-beta.2
Conditions can also be linked by logical OR:
<2.0.0 || >=3.0.0
would match1.x.x
and3.x.x
but not2.x.x
AND has a higher precedence than OR. It's not possible to use brackets.
Conditions can be combined with both AND and OR
>1.0.0 <2.0.0 || >3.0.0 !4.2.1
would match1.2.3
,1.9.9
,3.1.1
, but not4.2.1
,2.1.1
$ semver "1.0.2" ">=1.0.0"
1.0.2 meets the condition.
$ echo $?
0
$ semver "2.0.2" "<2.0.0 || >=3.0.0"
2.0.2 does not meet the condition!
$ echo $?
1
$ semver -q "1.9.9" ">1.0.0 <2.0.0 || >3.0.0 !4.2.1"
$ echo $?
0
This repository keeps a change log. The format of the log is based on Keep a Changelog.
Releases are based on Semantic Versioning, and use the format
of MAJOR.MINOR.PATCH
. In a nutshell, the version will be incremented
based on the following:
MAJOR
: Incompatible or major changes.MINOR
: Backwards-compatible new features and enhancements.PATCH
: Backwards-compatible bugfixes and package updates.
Got questions?
You could open an issue here GitHub.
This is an active open-source project. We are always open to people who want to use the code or contribute to it.
We have set up a separate document containing our contribution guidelines.
Thank you for being involved! 😍
The original setup of this repository is by Franck Nijhof.
For a full list of all authors and contributors, check the contributor's page.
MIT License
Copyright (c) 2017 Franck Nijhof
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.