From b30e898d823fdb67ae05112d1ef296b220bf0962 Mon Sep 17 00:00:00 2001 From: jolheiser Date: Tue, 25 Oct 2022 11:40:11 -0500 Subject: [PATCH] version flag Signed-off-by: jolheiser --- main.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/main.go b/main.go index f19e6a8..bdd1703 100644 --- a/main.go +++ b/main.go @@ -1,6 +1,9 @@ package main import ( + "flag" + "os" + "github.com/caarlos0/log" "github.com/charmbracelet/lipgloss" ) @@ -8,6 +11,19 @@ import ( var Version = "develop" func main() { + fs := flag.NewFlagSet("trending", flag.ExitOnError) + versionFlag := fs.Bool("version", false, "Show version and exit") + fs.BoolVar(versionFlag, "v", *versionFlag, "--version") + if err := fs.Parse(os.Args[1:]); err != nil { + log.WithError(err).Error("") + return + } + + if *versionFlag { + log.Infof("trending (%s)", Version) + return + } + cfg, err := loadConfig() if err != nil { log.WithError(err).Error("could not load config")