From 846ff16fb3715df339ed281d26b663b176a2016d Mon Sep 17 00:00:00 2001 From: Saeed Rasooli Date: Sun, 19 Jan 2025 18:52:49 +0330 Subject: [PATCH] add `-version` / `--version` flag --- main_gui.go | 12 ++++++++++++ main_no_gui.go | 12 ++++++++++++ 2 files changed, 24 insertions(+) diff --git a/main_gui.go b/main_gui.go index 8f80579..2766589 100644 --- a/main_gui.go +++ b/main_gui.go @@ -4,9 +4,11 @@ package main import ( "flag" + "fmt" "log/slog" "os" + "github.com/ilius/ayandict/v2/pkg/appinfo" "github.com/ilius/ayandict/v2/pkg/application" "github.com/ilius/ayandict/v2/pkg/config" "github.com/ilius/ayandict/v2/pkg/dictmgr" @@ -33,6 +35,11 @@ func runServerOnly(createConfig bool) { } func main() { + versionFlag := flag.Bool( + "version", + false, + "Show version and exit", + ) noGuiFlag := flag.Bool( "no-gui", false, @@ -45,6 +52,11 @@ func main() { ) flag.Parse() + if *versionFlag { + fmt.Printf("%v %v\n", appinfo.APP_DESC, appinfo.VERSION) + os.Exit(0) + } + // slog uses stdout noColor := os.Getenv("NO_COLOLR") != "" logging.SetupLogger(noColor, logging.DefaultLevel) diff --git a/main_no_gui.go b/main_no_gui.go index 9349f1f..58f4320 100644 --- a/main_no_gui.go +++ b/main_no_gui.go @@ -4,9 +4,11 @@ package main import ( "flag" + "fmt" "log/slog" "os" + "github.com/ilius/ayandict/v2/pkg/appinfo" "github.com/ilius/ayandict/v2/pkg/config" "github.com/ilius/ayandict/v2/pkg/dictmgr" "github.com/ilius/ayandict/v2/pkg/logging" @@ -16,6 +18,11 @@ import ( func main() { // slog uses stdout + versionFlag := flag.Bool( + "version", + false, + "Show version and exit", + ) createConfigFlag := flag.Bool( "create-config", false, @@ -23,6 +30,11 @@ func main() { ) flag.Parse() + if *versionFlag { + fmt.Printf("%v %v (non-GUI build)\n", appinfo.APP_DESC, appinfo.VERSION) + os.Exit(0) + } + conf, err := config.Load() if err != nil { panic(err)