mirror of
https://github.com/KevinMidboe/traefik-etcd-advertiser.git
synced 2025-10-29 18:00:19 +00:00
set and read CLI flags for filename & publish
This commit is contained in:
36
config/cli.go
Normal file
36
config/cli.go
Normal 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
|
||||
}
|
||||
Reference in New Issue
Block a user