package main import ( "flag" "fmt" "os" ) // Flags supplied to the cli. type Flags struct { ConfigPath string Discover bool Verbose bool } // ParseFlags parses the supplied command-line flags. func (a *App) ParseFlags() { app.flags = new(Flags) flag.Usage = func() { fmt.Printf(serviceName + ": " + serviceDescription + ".\n\nUsage:\n") flag.PrintDefaults() } // Print the version and exit when requested. var printVersion bool flag.BoolVar(&printVersion, "v", false, "Print version") // Override the configuration path. usage := "Load configuration from `FILE`" flag.StringVar(&app.flags.ConfigPath, "config", "", usage) flag.StringVar(&app.flags.ConfigPath, "c", "", usage+" (shorthand)") // Query each configured device for its integration IDs and exit. usage = "Connect to each device, print its integration IDs, and exit" flag.BoolVar(&app.flags.Discover, "discover", false, usage) flag.BoolVar(&app.flags.Discover, "d", false, usage+" (shorthand)") // Force debug-level logging to the console, overriding the configured log level. usage = "Force debug-level logging to the console, overriding the config" flag.BoolVar(&app.flags.Verbose, "verbose", false, usage) flag.BoolVar(&app.flags.Verbose, "V", false, usage+" (shorthand)") flag.Parse() if printVersion { fmt.Println(serviceName + ": " + serviceVersion) os.Exit(0) } }