commit 2cc904815a8893d76a53c0c38d6f6162c1039920 Author: Knut Ahlers Date: Mon Jul 6 23:22:49 2020 +0200 Initial version diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..14817a2 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +vercmp diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..1e9858b --- /dev/null +++ b/LICENSE @@ -0,0 +1,25 @@ +This is free and unencumbered software released into the public domain. + +Anyone is free to copy, modify, publish, use, compile, sell, or +distribute this software, either in source code form or as a compiled +binary, for any purpose, commercial or non-commercial, and by any +means. + +In jurisdictions that recognize copyright laws, the author or authors +of this software dedicate any and all copyright interest in the +software to the public domain. We make this dedication for the benefit +of the public at large and to the detriment of our heirs and +successors. We intend this dedication to be an overt act of +relinquishment in perpetuity of all present and future rights to this +software under copyright law. + +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 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. + +For more information, please refer to + diff --git a/README.md b/README.md new file mode 100644 index 0000000..d13f885 --- /dev/null +++ b/README.md @@ -0,0 +1,27 @@ +[![Go Report Card](https://goreportcard.com/badge/github.com/Luzifer/vercmp)](https://goreportcard.com/report/github.com/Luzifer/vercmp) +![](https://badges.fyi/github/license/Luzifer/vercmp) +![](https://badges.fyi/github/downloads/Luzifer/vercmp) +![](https://badges.fyi/github/latest-release/Luzifer/vercmp) +![](https://knut.in/project-status/vercmp) + +# Luzifer / vercmp + +`vercmp` resembles [`vercmp`](https://www.archlinux.org/pacman/vercmp.8.html) utility from [Archlinux](https://www.archlinux.org/) with two small differences: It runs on systems without `libalpm.so` and it strictly uses [SemVer](https://semver.org/) - otherwise it should be fully interchangeable. + +## Usage + +```console +# vercmp + +Compare version numbers using SemVer version logic + +Usage: vercmp + +Output values: + < 0 : if ver1 < ver2 + 0 : if ver1 == ver2 + > 0 : if ver1 > ver2 + +# vercmp 7.6.0 7.4.1 +1 +``` diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..590db30 --- /dev/null +++ b/go.mod @@ -0,0 +1,8 @@ +module github.com/Luzifer/vercmp + +go 1.14 + +require ( + github.com/Luzifer/rconfig/v2 v2.2.1 + github.com/blang/semver/v4 v4.0.0 +) diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..e5e1cc3 --- /dev/null +++ b/go.sum @@ -0,0 +1,11 @@ +github.com/Luzifer/rconfig/v2 v2.2.1 h1:zcDdLQlnlzwcBJ8E0WFzOkQE1pCMn3EbX0dFYkeTczg= +github.com/Luzifer/rconfig/v2 v2.2.1/go.mod h1:OKIX0/JRZrPJ/ZXXWklQEFXA6tBfWaljZbW37w+sqBw= +github.com/blang/semver/v4 v4.0.0 h1:1PFHFE6yCCTv8C1TeyNNarDzntLi7wMI5i/pzqYIsAM= +github.com/blang/semver/v4 v4.0.0/go.mod h1:IbckMUScFkM3pff0VJDNKRiT6TG/YpiHIM2yvyW5YoQ= +github.com/spf13/pflag v1.0.3 h1:zPAT6CGy6wXeQ7NtTnaTerfKOsV6V6F8agHXFiazDkg= +github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/validator.v2 v2.0.0-20180514200540-135c24b11c19 h1:WB265cn5OpO+hK3pikC9hpP1zI/KTwmyMFKloW9eOVc= +gopkg.in/validator.v2 v2.0.0-20180514200540-135c24b11c19/go.mod h1:o4V0GXN9/CAmCsvJ0oXYZvrZOe7syiDZSN1GWGZTGzc= +gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw= +gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= diff --git a/main.go b/main.go new file mode 100644 index 0000000..0f0f92b --- /dev/null +++ b/main.go @@ -0,0 +1,60 @@ +package main + +import ( + "fmt" + "log" + "os" + + "github.com/blang/semver/v4" + + "github.com/Luzifer/rconfig/v2" +) + +const usage = ` +Compare version numbers using SemVer version logic + +Usage: vercmp + +Output values: + < 0 : if ver1 < ver2 + 0 : if ver1 == ver2 + > 0 : if ver1 > ver2 +` + +var ( + cfg = struct { + VersionAndExit bool `flag:"version" default:"false" description:"Prints current version and exits"` + }{} + + version = "dev" +) + +func init() { + if err := rconfig.ParseAndValidate(&cfg); err != nil { + log.Fatalf("Unable to parse commandline options: %s", err) + } + + if cfg.VersionAndExit { + fmt.Printf("vercmp %s\n", version) + os.Exit(0) + } +} + +func main() { + if len(rconfig.Args()) != 3 { + fmt.Println(usage) + os.Exit(2) + } + + ver1, err := semver.Make(rconfig.Args()[1]) + if err != nil { + log.Fatalf("Unable to parse ver1: %s", err) + } + + ver2, err := semver.Make(rconfig.Args()[2]) + if err != nil { + log.Fatalf("Unable to parse ver2: %s", err) + } + + fmt.Println(ver1.Compare(ver2)) +}