feat(cmd): add version flag (#822)

This commit is contained in:
ayn2op 2026-07-30 23:37:01 -04:00 • committed by GitHub
parent ccfaaa52e8
commit 93a137d982
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 24 additions and 0 deletions

View file

@ -17,8 +17,14 @@ func Run() error {
configPath := flag.String("config-path", config.DefaultPath(), "path of the configuration file")
logPath := flag.String("log-path", logger.DefaultPath(), "path of the log file")
logLevel := flag.String("log-level", "info", "log level")
showVersion := flag.Bool("version", false, "print version and exit")
flag.Parse()
if *showVersion {
fmt.Printf("%s\n", buildVersion())
return nil
}
var level slog.Level
switch *logLevel {
case "debug":

18
cmd/version.go Normal file
View 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
}
}