diff options
| author | Shulhan <ms@kilabit.info> | 2022-08-07 01:00:42 +0700 |
|---|---|---|
| committer | Shulhan <ms@kilabit.info> | 2022-08-07 01:00:42 +0700 |
| commit | dbfed69ca90f5cd02b969fd714a35acc80f5f703 (patch) | |
| tree | 49f3cb95a2c6ffec7e04ff1f75dd6915d6f86286 | |
| parent | f0831230b4578a580ae207e446654ca39c95a550 (diff) | |
| download | gotp-dbfed69ca90f5cd02b969fd714a35acc80f5f703.tar.xz | |
cmd/gotp: add subcommand "version"
The "version" command print the module version based on the latest tag,
with additional commit number and hash.
| -rw-r--r-- | .gitignore | 1 | ||||
| -rw-r--r-- | Makefile | 18 | ||||
| -rw-r--r-- | cmd/gotp/main.go | 6 | ||||
| -rw-r--r-- | gotp.go | 4 |
4 files changed, 25 insertions, 4 deletions
@@ -1,6 +1,7 @@ // SPDX-FileCopyrightText: 2021 M. Shulhan <ms@kilabit.info> // SPDX-License-Identifier: GPL-3.0-or-later README.html +_bin/ cover.html cover.out testdata/add.conf @@ -1,10 +1,20 @@ ## SPDX-FileCopyrightText: 2021 M. Shulhan <ms@kilabit.info> ## SPDX-License-Identifier: GPL-3.0-or-later -.PHONY: all install -all: +.PHONY: all test build install + +VERSION:=$(shell git describe --tags) +LDFLAGS:=-ldflags "-s -w -X 'git.sr.ht/~shulhan/gotp.Version=$(VERSION)'" + +all: test build + +test: CGO_ENABLED=1 go test -race -failfast -coverprofile=cover.out ./... go tool cover -html=cover.out -o cover.out -install: - go install ./cmd/gotp +build: + mkdir -p _bin/ + go build $(LDFLAGS) -o _bin/ ./cmd/... + +install: build + install -m755 _bin/gotp $(GOBIN)/ diff --git a/cmd/gotp/main.go b/cmd/gotp/main.go index f031e8b..f159234 100644 --- a/cmd/gotp/main.go +++ b/cmd/gotp/main.go @@ -22,6 +22,7 @@ const ( cmdList = `list` cmdRemove = `remove` cmdRename = `rename` + cmdVersion = `version` ) func main() { @@ -76,6 +77,11 @@ func main() { log.Printf(`%s %s: missing parameters`, cmdName, cmd) os.Exit(1) } + + case cmdVersion: + fmt.Println(`gotp v`, gotp.Version) + return + default: log.Printf(`%s: unknown command %q`, cmdName, cmd) flag.Usage() @@ -24,6 +24,10 @@ const ( providerNameAegis = `aegis` ) +var ( + Version = `0.2.0` +) + // normalizeLabel convert non alpha number, hyphen, underscore, or period // characters into `-`. func normalizeLabel(in string) (out string) { |
