1
0
Fork 0
mirror of https://github.com/Luzifer/vercmp.git synced 2024-10-18 05:54:22 +00:00

Initial version

This commit is contained in:
Knut Ahlers 2020-07-06 23:22:49 +02:00
commit 2cc904815a
Signed by: luzifer
GPG key ID: DC2729FDD34BE99E
6 changed files with 132 additions and 0 deletions

1
.gitignore vendored Normal file
View file

@ -0,0 +1 @@
vercmp

25
LICENSE Normal file
View file

@ -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 <https://unlicense.org>

27
README.md Normal file
View file

@ -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 <ver1> <ver2>
Output values:
< 0 : if ver1 < ver2
0 : if ver1 == ver2
> 0 : if ver1 > ver2
# vercmp 7.6.0 7.4.1
1
```

8
go.mod Normal file
View file

@ -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
)

11
go.sum Normal file
View file

@ -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=

60
main.go Normal file
View file

@ -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 <ver1> <ver2>
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))
}