lutron-control/flags.go
James Coleman b39600f64a
Some checks failed
Go package / build (push) Has been cancelled
Add scene-select channels, MQTT override, and release tooling; bump to 0.1.1
Restore uncommitted work from earlier sessions: DMX scene-select channels,
MQTT override handling, configurable zone refresh interval, OSC additions,
and matching tests and docs.

Add versioning following nginx-cache-purge: VERSION file, ldflags-stamped
build identifiers in info.go, Makefile, GoReleaser config, GitHub workflows,
and a -version flag using the standard flag package.

Claude-Session: https://claude.ai/code/session_01C5ZxhELATettecwYcNiXVN
2026-08-25 21:15:33 -05:00

77 lines
2.1 KiB
Go

package main
import (
"flag"
"fmt"
"os"
"runtime/debug"
)
// Flags supplied to the cli.
type Flags struct {
ConfigPath string
Discover bool
Verbose bool
}
// printVersion emits version and build information to stdout.
func printVersion() {
fmt.Printf("%s: %s (%s)\n", Name, Version, Mode)
if Commit != "" {
fmt.Printf(" commit: %s\n", Commit)
}
if Date != "" {
fmt.Printf(" built: %s\n", Date)
}
// Without build stamps, a module-aware build still records the revision
// it was built from, so fall back to what the toolchain embedded.
if Commit == "" {
if bi, ok := debug.ReadBuildInfo(); ok {
for _, s := range bi.Settings {
switch s.Key {
case "vcs.revision":
fmt.Printf(" commit: %s\n", s.Value)
case "vcs.time":
fmt.Printf(" built: %s\n", s.Value)
}
}
}
}
}
// ParseFlags parses the supplied command-line flags.
func (a *App) ParseFlags() {
app.flags = new(Flags)
flag.Usage = func() {
fmt.Printf(Name + ": " + Description + ".\n\nUsage:\n")
flag.PrintDefaults()
}
// Print the version and exit when requested.
var showVersion bool
usage := "Print version information and quit"
flag.BoolVar(&showVersion, "version", false, usage)
flag.BoolVar(&showVersion, "v", false, usage+" (shorthand)")
// 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 showVersion {
printVersion()
os.Exit(0)
}
}