Gentoo versioning format (scheme) is like Semantic Versioning, but more flexible and complex. It was designed to be compatible with various versioning formats used in open-source projects. This format is used also in Alpine Linux.
This library allows to parse, normalize, validate and compare version numbers.
local ver = require "gversion"
-- Parse version
local pkgver = ver.parse("2.1_rc3-r1")
local pkgver = ver"2.1_rc3-r1"
-- Access version components
pkgver[1] --> "2"
pkgver.major --> "2"
pkgver[2] --> "1"
pkgver.minor --> "1"
pkgver.rc --> "3"
pkgver.r --> "1"
-- Change version components
pkgver[1] = "2" -- 2.1_rc3-r1
pkgver.minor = "0" -- 2.0_rc3-r1
pkgver.rc = nil -- 2.0-r1
-- Compare versions
ver"1.5" == ver"1.005" --> true
ver"1.2_rc1" < ver"1.2b" --> true
ver"1.2_beta_pre" > ver"1.2_p1" --> false
-- Normalize version; try to convert it into our versioning format
ver.normalize("2_1-beta3") --> "2.1_beta3"
ver.normalize("2.1b3") --> "2.1_beta3"
You can install gversion using LuaRocks (the Lua package manager):
luarocks install gversion
or to get the latest development version:
luarocks install --server=http://luarocks.org/dev gversion
Note: If you want to bootstrap development environment for running tests, read the next section.
-
Clone this repository:
git clone https://github.com/jirutka/gversion.lua.git cd gversion.lua
-
Source file
.envrc
into your shell (or manually add$(pwd)/.venv/bin
to yourPATH
):source .envrc
-
Install Lua and modules for running tests into directory
.venv
:./script/bootstrap
-
Start hacking!
-
Run tests with code coverage and linter:
./script/test
This project is licensed under MIT License. For the full text of the license, see the LICENSE file.