Skip to content

Commit

Permalink
Show version with -version CLI flag
Browse files Browse the repository at this point in the history
  • Loading branch information
chelmertz committed Dec 13, 2023
1 parent d4c5ca9 commit fc8d5fb
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main
import (
"errors"
"flag"
"fmt"
"os"
"regexp"
"runtime/debug"
Expand All @@ -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 == "" {
Expand All @@ -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),
Expand Down

0 comments on commit fc8d5fb

Please sign in to comment.