1
0
mirror of https://github.com/mgechev/revive.git synced 2024-11-24 08:32:22 +02:00

Add version command to show binary build info (#506)

add version cli flag to show binary build info
This commit is contained in:
Ahmed 2021-03-23 20:45:31 +01:00 committed by GitHub
parent 46f65914e3
commit 7abb883d0f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

23
main.go
View File

@ -15,6 +15,13 @@ import (
"github.com/mitchellh/go-homedir"
)
var (
version = "dev"
commit = "none"
date = "unknown"
builtBy = "unknown"
)
func fail(err string) {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
@ -132,6 +139,7 @@ var configPath string
var excludePaths arrayFlags
var formatterName string
var help bool
var versionFlag bool
var originalUsage = flag.Usage
@ -177,11 +185,13 @@ func init() {
fmt.Println(getBanner())
originalUsage()
}
// command line help strings
const (
configUsage = "path to the configuration TOML file, defaults to $HOME/revive.toml, if present (i.e. -config myconf.toml)"
excludeUsage = "list of globs which specify files to be excluded (i.e. -exclude foo/...)"
formatterUsage = "formatter to be used for the output (i.e. -formatter stylish)"
versionUsage = "get revive version"
)
defaultConfigPath := buildDefaultConfigPath()
@ -189,5 +199,18 @@ func init() {
flag.StringVar(&configPath, "config", defaultConfigPath, configUsage)
flag.Var(&excludePaths, "exclude", excludeUsage)
flag.StringVar(&formatterName, "formatter", "", formatterUsage)
flag.BoolVar(&versionFlag, "version", false, versionUsage)
flag.Parse()
// Output build info (version, commit, date and builtBy)
if versionFlag {
fmt.Printf(
"Current revive version %v commit %v, built @%v by %v.\n",
version,
commit,
date,
builtBy,
)
os.Exit(0)
}
}