Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add version command to show binary build info #506

Merged
merged 2 commits into from Mar 23, 2021
Merged

Add version command to show binary build info #506

merged 2 commits into from Mar 23, 2021

Conversation

Clivern
Copy link
Contributor

@Clivern Clivern commented Mar 22, 2021

This PR adds a command to show version. goreleaser already pass these info during build time so releases will have them by default from now on.

For manual builds, you can provide them:

$ go build -v -ldflags="-X 'main.version=v1.0.0' -X 'main.commit=46f65914e3b26f7044ffe6842ecce10b58e2c2aa' -X 'main.date=2021-03-21T21:37:16Z' -X 'main.builtBy=goreleaser'"

$ ./revive --version
Current revive version v1.0.0 commit 46f65914e3b26f7044ffe6842ecce10b58e2c2aa, built @2021-03-21T21:37:16Z by goreleaser.

# If not there, it will be unknown
$ go build
$ ./revive --version
Current revive version dev commit none, built @unknown by unknown.

Closes #381

@chavacava
Copy link
Collaborator

Hi @Clivern, thanks for the PR
What do you think about implementing the version flag as the other flags were implemented? That way we will also accept -version and --version
Something like

...
	defaultConfigPath := buildDefaultConfigPath()
	var versionFlag bool

	flag.StringVar(&configPath, "config", defaultConfigPath, configUsage)
	flag.Var(&excludePaths, "exclude", excludeUsage)
	flag.StringVar(&formatterName, "formatter", "", formatterUsage)
	flag.BoolVar(&versionFlag, "version", false, versionUsage)
	flag.Parse()

	if versionFlag {
		fmt.Printf(
			"revive version %v commit %v, built @%v by %v.\n",
			version,
			commit,
			date,
			builtBy,
		)
		os.Exit(0)
	}

@Clivern
Copy link
Contributor Author

Clivern commented Mar 22, 2021

@chavacava i am fine with both and it's updated to use flags.
i was trying to separate it from revive run flags to be a command argument but couldn't find a nice way.

@chavacava chavacava merged commit 7abb883 into mgechev:master Mar 23, 2021
@chavacava
Copy link
Collaborator

thanks @Clivern !

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.

Application version support
2 participants