Skip to content

Commit

Permalink
feat: Add -version CLI argument
Browse files Browse the repository at this point in the history
Signed-off-by: Steffen Vogel <post@steffenvogel.de>
  • Loading branch information
stv0g committed Nov 7, 2024
1 parent 0cbc25c commit 32439eb
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
6 changes: 5 additions & 1 deletion cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
16 changes: 10 additions & 6 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit 32439eb

Please sign in to comment.