From 2d8673420d0d62442455b8d4e0c4796af0b91af4 Mon Sep 17 00:00:00 2001 From: Ishan Goel Date: Mon, 6 Mar 2023 12:13:37 -0800 Subject: [PATCH] add version option --- .goreleaser.yml | 2 +- README.md | 6 +++--- cmd/aces/main.go | 13 ++++++++++--- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/.goreleaser.yml b/.goreleaser.yml index f0765b1..04a9652 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -16,7 +16,7 @@ builds: - 386 main: ./cmd/aces ldflags: - - -s -w + - -s -w -X main.version=v{{.Version}} # -X main.commit={{.Commit}} -X main.date={{.Date}} ignore: # problems with build - goos: windows goarch: arm64 diff --git a/README.md b/README.md index 58703ec..3b1de99 100644 --- a/README.md +++ b/README.md @@ -65,9 +65,9 @@ Head over to [releases](https://github.com/quackduck/aces/releases) and download Aces - Encode in any character set Usage: - aces - encode data from STDIN into - aces -d/--decode - decode data from STDIN from - aces -h/--help - print this help message + aces - encode data from STDIN into + aces -d/--decode - decode data from STDIN from + aces -v/--version | -h/--help - print version or this help message Aces reads from STDIN for your data and outputs the result to STDOUT. An optimized algorithm is used for character sets with a power of 2 length. Newlines are ignored when decoding. diff --git a/cmd/aces/main.go b/cmd/aces/main.go index 9a810ad..2ecf7d8 100644 --- a/cmd/aces/main.go +++ b/cmd/aces/main.go @@ -12,9 +12,9 @@ var ( helpMsg = `Aces - Encode in any character set Usage: - aces - encode data from STDIN into - aces -d/--decode - decode data from STDIN from - aces -h/--help - print this help message + aces - encode data from STDIN into + aces -d/--decode - decode data from STDIN from + aces -v/--version | -h/--help - print version or this help message Aces reads from STDIN for your data and outputs the result to STDOUT. An optimized algorithm is used for character sets with a power of 2 length. Newlines are ignored when decoding. @@ -31,6 +31,7 @@ Examples: Set the encoding/decoding buffer size with --bufsize (default 16KiB). File issues, contribute or star at github.com/quackduck/aces` + version = "dev" ) func main() { @@ -60,6 +61,12 @@ func main() { fmt.Println(helpMsg) return } + + if os.Args[1] == "-v" || os.Args[1] == "--version" { + fmt.Println("Aces " + version) + return + } + decode := os.Args[1] == "--decode" || os.Args[1] == "-d" if decode { if len(os.Args) == 2 {