go-toolkit
go-toolkit copied to clipboard
Proposal to Add -v or --version Parameter to CLI Interface
I would like to propose the addition of a new parameter, either -v or --version, to the command-line interface (CLI) of our tool. This parameter would allow users to quickly retrieve information about the version of the tool they are using.
Currently, when working with the CLI, it can be cumbersome to find the version of the tool.
Sure, good idea.
I would avoid hard-coding the current version though. We can use this snippet during build time to get the version number from the Git tags:
git describe --tags --match v[0-9]* 2> /dev/null
Cool thing is that between two versions you still get a descriptive version number, e.g. v0.11.1-2-gab1d8fd
This is very easy to do using goreleaser (which we already use). See https://goreleaser.com/cookbooks/using-main.version/ That might be all we need, but can also be overridden, e.g.
ldflags:
- -s -w -X github.com/xxx/yyy/internal/consts.BuildCommit={{.Commit}} -X github.com/xxx/yyy/internal/consts.BuildTimestamp={{.Timestamp}}
Suggestion: https://github.com/carlmjohnson/versioninfo https://blog.carlmjohnson.net/post/2023/golang-git-hash-how-to/