Skip to content

Add --version flag#163

Open
piersdd wants to merge 1 commit intotailscale:mainfrom
piersdd:feat/version-flag
Open

Add --version flag#163
piersdd wants to merge 1 commit intotailscale:mainfrom
piersdd:feat/version-flag

Conversation

@piersdd
Copy link
Copy Markdown

@piersdd piersdd commented Apr 2, 2026

Adds a version variable set at build time via ldflags and a --version flag that prints it and exits.

  • var version = "dev" default, overridden by -X main.version=...
  • Checked before flag.Parse() so it doesn't conflict with the flag package
  • Makefile passes -X main.version=$(VERSION) using git describe

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.
Comment thread tsidp-server.go
func main() {
ctx := context.Background()

if len(os.Args) == 2 && os.Args[1] == "--version" {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@ScrappyXII
Copy link
Copy Markdown
Contributor

ScrappyXII commented Apr 20, 2026

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.

Comment thread tsidp-server.go
)

// version is set at build time via -ldflags "-X main.version=..."
var version = "dev"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

given this imports Tailscale.com/version ... is this more a buildVersion?

@mikeodr
Copy link
Copy Markdown
Collaborator

mikeodr commented Apr 23, 2026

Believe #165 supersedes this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants