From 58d75bfc5a0d276aeb436f1e9528a44e31c14159 Mon Sep 17 00:00:00 2001 From: mleku Date: Wed, 3 Dec 2025 10:23:39 +0000 Subject: [PATCH] add version command --- app/config/config.go | 18 +++++++++++++++++- main.go | 7 +++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/app/config/config.go b/app/config/config.go index 00390e5..eb1b057 100644 --- a/app/config/config.go +++ b/app/config/config.go @@ -233,6 +233,21 @@ func ServeRequested() (requested bool) { return } +// VersionRequested checks if the first command line argument is "version" and returns +// whether the version should be printed and the program should exit. +// +// Return Values +// - requested: true if the 'version' subcommand was provided, false otherwise. +func VersionRequested() (requested bool) { + if len(os.Args) > 1 { + switch strings.ToLower(os.Args[1]) { + case "version", "-v", "--v", "-version", "--version": + requested = true + } + } + return +} + // KV is a key/value pair. type KV struct{ Key, Value string } @@ -364,7 +379,7 @@ func PrintHelp(cfg *C, printer io.Writer) { ) _, _ = fmt.Fprintf( printer, - `Usage: %s [env|help|identity|serve] + `Usage: %s [env|help|identity|serve|version] - env: print environment variables configuring %s - help: print this help text @@ -372,6 +387,7 @@ func PrintHelp(cfg *C, printer io.Writer) { - serve: start ephemeral relay with RAM-based storage at /dev/shm/orlyserve listening on 0.0.0.0:10547 with 'none' ACL mode (open relay) useful for testing and benchmarking +- version: print version and exit (also: -v, --v, -version, --version) `, cfg.AppName, cfg.AppName, diff --git a/main.go b/main.go index ea15feb..a109cf7 100644 --- a/main.go +++ b/main.go @@ -31,6 +31,13 @@ import ( func main() { runtime.GOMAXPROCS(128) debug.SetGCPercent(10) + + // Handle 'version' subcommand early, before any other initialization + if config.VersionRequested() { + fmt.Println(version.V) + os.Exit(0) + } + var err error var cfg *config.C if cfg, err = config.New(); chk.T(err) {