From 2d6f4db38edb46a43672e331a81112a048c6346c Mon Sep 17 00:00:00 2001 From: Solderpunk Date: Sun, 5 Feb 2023 15:36:18 +0100 Subject: [PATCH] Add -v flag to print version and exit. Closes #23. --- main.go | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/main.go b/main.go index a616351..6df0278 100644 --- a/main.go +++ b/main.go @@ -3,17 +3,30 @@ package main import ( "crypto/tls" "flag" + "fmt" "log" "os" "strconv" ) +var VERSION = "0.0.0" + func main() { var conf_file string + var version bool - // Parse args and read config + // Parse args flag.StringVar(&conf_file, "c", "", "Path to config file") + flag.BoolVar(&version, "v", false, "Print version and exit") flag.Parse() + + // If requested, print version and exit + if version { + fmt.Println("Molly Brown version", VERSION) + os.Exit(0) + } + + // Read config if conf_file == "" { _, err := os.Stat("/etc/molly.conf") if err == nil {