Skip to content

Commit 7abb883

Browse files
authored
Add version command to show binary build info (#506)
add version cli flag to show binary build info
1 parent 46f6591 commit 7abb883

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

main.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,13 @@ import (
1515
"github.com/mitchellh/go-homedir"
1616
)
1717

18+
var (
19+
version = "dev"
20+
commit = "none"
21+
date = "unknown"
22+
builtBy = "unknown"
23+
)
24+
1825
func fail(err string) {
1926
fmt.Fprintln(os.Stderr, err)
2027
os.Exit(1)
@@ -132,6 +139,7 @@ var configPath string
132139
var excludePaths arrayFlags
133140
var formatterName string
134141
var help bool
142+
var versionFlag bool
135143

136144
var originalUsage = flag.Usage
137145

@@ -177,17 +185,32 @@ func init() {
177185
fmt.Println(getBanner())
178186
originalUsage()
179187
}
188+
180189
// command line help strings
181190
const (
182191
configUsage = "path to the configuration TOML file, defaults to $HOME/revive.toml, if present (i.e. -config myconf.toml)"
183192
excludeUsage = "list of globs which specify files to be excluded (i.e. -exclude foo/...)"
184193
formatterUsage = "formatter to be used for the output (i.e. -formatter stylish)"
194+
versionUsage = "get revive version"
185195
)
186196

187197
defaultConfigPath := buildDefaultConfigPath()
188198

189199
flag.StringVar(&configPath, "config", defaultConfigPath, configUsage)
190200
flag.Var(&excludePaths, "exclude", excludeUsage)
191201
flag.StringVar(&formatterName, "formatter", "", formatterUsage)
202+
flag.BoolVar(&versionFlag, "version", false, versionUsage)
192203
flag.Parse()
204+
205+
// Output build info (version, commit, date and builtBy)
206+
if versionFlag {
207+
fmt.Printf(
208+
"Current revive version %v commit %v, built @%v by %v.\n",
209+
version,
210+
commit,
211+
date,
212+
builtBy,
213+
)
214+
os.Exit(0)
215+
}
193216
}

0 commit comments

Comments
 (0)