From fc8d5fb59ba945864ace7b9258b1406a0c056107 Mon Sep 17 00:00:00 2001 From: Calle Helmertz Date: Wed, 13 Dec 2023 14:10:38 +0100 Subject: [PATCH] Show version with -version CLI flag --- main.go | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/main.go b/main.go index 5f6beba..4787942 100644 --- a/main.go +++ b/main.go @@ -3,6 +3,7 @@ package main import ( "errors" "flag" + "fmt" "os" "regexp" "runtime/debug" @@ -18,12 +19,26 @@ import ( var timeoutMinutes = flag.Int("timeout", 10, "refresh PRs every N minutes") var url = flag.String("url", "localhost:9876", "URL for web GUI") +var versionFlag = flag.Bool("version", false, "show version") var logger = slog.New(slog.NewTextHandler(os.Stdout, nil)) var githubUsernameRegex = regexp.MustCompile("[a-zA-Z0-9-]+") func main() { flag.Parse() + var version string + if bi, ok := debug.ReadBuildInfo(); ok { + version = bi.Main.Version + } + if version == "" { + version = "unknown" + } + + if *versionFlag { + fmt.Println(version) + os.Exit(0) + } + // TODO try out with bad github pat and make sure it fails gracefully (and is shown in GUI) token := os.Getenv("GITHUB_PAT") if token == "" { @@ -43,11 +58,6 @@ func main() { os.Exit(1) } - version := "unknown" - if bi, ok := debug.ReadBuildInfo(); ok { - version = bi.Main.Version - } - logger.Info("starting elly", slog.String("github_user", username), slog.String("version", version),