From 32439eb9f11b0aa9372f77248219a0e187eedc88 Mon Sep 17 00:00:00 2001 From: Steffen Vogel Date: Thu, 7 Nov 2024 07:54:33 +0100 Subject: [PATCH] feat: Add -version CLI argument Signed-off-by: Steffen Vogel --- cmd/main.go | 6 +++++- pkg/config/config.go | 16 ++++++++++------ 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/cmd/main.go b/cmd/main.go index f49d573..ceb29ef 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -33,11 +33,15 @@ func main() { // Generate our config based on the config supplied // by the user in the flags. - cfgFile, err := config.ParseFlags() + cfgFile, showVersion, err := config.ParseFlags() if err != nil { log.Fatal(err) } + if showVersion { + return + } + cfg, err := config.NewConfig(cfgFile) if err != nil { log.Fatal(err) diff --git a/pkg/config/config.go b/pkg/config/config.go index ac64d78..a1c4fb8 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -274,17 +274,21 @@ func (c *Config) Check() error { // ParseFlags will create and parse the CLI flags // and return the path to be used elsewhere. -func ParseFlags() (string, error) { - // String that contains the configured configuration path +func ParseFlags() (string, bool, error) { + // String that contains the configured configuration path. var configPath string + var showVersion bool // Set up a CLI flag called "-config" to allow users - // to supply the configuration file + // to supply the configuration file. flag.StringVar(&configPath, "config", "", "path to config file") - // Actually parse the flags + // Set up a CLI flag called "-version" to print the programs version and build details. + flag.BoolVar(&showVersion, "version", false, "show version information") + + // Actually parse the flags. flag.Parse() - // Return the configuration path - return configPath, nil + // Return the configuration path. + return configPath, showVersion, nil }