Add --version flag#163
Conversation
Adds a `version` variable set at build time via ldflags and a `--version` flag that prints it and exits. Checked before flag.Parse() so it doesn't conflict with the flag package. Makefile updated to pass `-X main.version=$(VERSION)` using git describe.
| func main() { | ||
| ctx := context.Background() | ||
|
|
||
| if len(os.Args) == 2 && os.Args[1] == "--version" { |
There was a problem hiding this comment.
This only handles the exact invocation tsidp-server --version. It silently ignores:
- tsidp-server -version (single dash, which flag accepts for any flag)
- tsidp-server --version --port 443 (version mixed with other flags)
The idiomatic Go approach is to register it as a proper flag:
flagVersion = flag.Bool("version", false, "print version and exit")
Then after flag.Parse(), check *flagVersion. This integrates naturally with -help output too — right now --version doesn't appear in tsidp-server --help.
|
Something to consider: The Makefile change only helps local builds. The Dockerfile isn't updated to pass --build-arg VERSION=... or inject the ldflag during docker build. Users running the Docker image (the majority, given the issue count around Docker) will always see "dev". For context, this is probably the primary use case for issue #157 (version visible on dashboard/container) for which there is also a version related PR. |
| ) | ||
|
|
||
| // version is set at build time via -ldflags "-X main.version=..." | ||
| var version = "dev" |
There was a problem hiding this comment.
given this imports Tailscale.com/version ... is this more a buildVersion?
|
Believe #165 supersedes this. |
Adds a
versionvariable set at build time via ldflags and a--versionflag that prints it and exits.var version = "dev"default, overridden by-X main.version=...flag.Parse()so it doesn't conflict with the flag package-X main.version=$(VERSION)usinggit describe