set and read CLI flags for filename & publish

This commit is contained in:
2025-01-18 12:08:26 +01:00
parent b885893879
commit a6c909a673
2 changed files with 42 additions and 12 deletions

36
config/cli.go Normal file
View File

@@ -0,0 +1,36 @@
package config
import (
"flag"
"fmt"
"os"
)
var (
filename string
)
func ParseCli() (string, *bool) {
flag.StringVar(&filename, "filename", "", "path of config")
publish := flag.Bool("publish", false, "publish etcd messages")
flag.Parse()
args := os.Args[1:]
if len(args) == 0 {
// no command, exit with code 2 (invalid usage)
fmt.Fprintf(os.Stderr, "Usage of %s:\n", os.Args[0])
flag.PrintDefaults()
os.Exit(2)
}
if len(filename) < 1 {
fmt.Fprintf(os.Stderr, "Filename required. Usage:\n")
flag.PrintDefaults()
os.Exit(2)
}
return filename, publish
}