feat(cmd): add version flag (#822)
This commit is contained in:
parent
ccfaaa52e8
commit
93a137d982
2 changed files with 24 additions and 0 deletions
|
|
@ -17,8 +17,14 @@ func Run() error {
|
||||||
configPath := flag.String("config-path", config.DefaultPath(), "path of the configuration file")
|
configPath := flag.String("config-path", config.DefaultPath(), "path of the configuration file")
|
||||||
logPath := flag.String("log-path", logger.DefaultPath(), "path of the log file")
|
logPath := flag.String("log-path", logger.DefaultPath(), "path of the log file")
|
||||||
logLevel := flag.String("log-level", "info", "log level")
|
logLevel := flag.String("log-level", "info", "log level")
|
||||||
|
showVersion := flag.Bool("version", false, "print version and exit")
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
|
if *showVersion {
|
||||||
|
fmt.Printf("%s\n", buildVersion())
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
var level slog.Level
|
var level slog.Level
|
||||||
switch *logLevel {
|
switch *logLevel {
|
||||||
case "debug":
|
case "debug":
|
||||||
|
|
|
||||||
18
cmd/version.go
Normal file
18
cmd/version.go
Normal file
|
|
@ -0,0 +1,18 @@
|
||||||
|
package cmd
|
||||||
|
|
||||||
|
import (
|
||||||
|
"runtime/debug"
|
||||||
|
)
|
||||||
|
|
||||||
|
func buildVersion() string {
|
||||||
|
info, ok := debug.ReadBuildInfo()
|
||||||
|
if !ok {
|
||||||
|
return "unknown"
|
||||||
|
}
|
||||||
|
switch info.Main.Version {
|
||||||
|
case "", "(devel)":
|
||||||
|
return "v0.0.0-dev"
|
||||||
|
default:
|
||||||
|
return info.Main.Version
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Add table
Reference in a new issue