go-toolkit icon indicating copy to clipboard operation
go-toolkit copied to clipboard

Proposal to Add -v or --version Parameter to CLI Interface

Open gregoriopellegrino opened this issue 2 years ago • 3 comments

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.

gregoriopellegrino avatar Jun 27 '23 15:06 gregoriopellegrino

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

mickael-menu avatar Jun 27 '23 15:06 mickael-menu

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}}

chocolatkey avatar Jun 27 '23 15:06 chocolatkey

Suggestion: https://github.com/carlmjohnson/versioninfo https://blog.carlmjohnson.net/post/2023/golang-git-hash-how-to/

atomotic avatar Jun 28 '23 06:06 atomotic