Clean up subcommand registrations

This commit is contained in:
Ryan Cavicchioni 2021-01-31 19:40:27 -06:00
parent 320815293d
commit 9321095e11
Signed by: ryanc
GPG Key ID: 877EEDAF9245103D
8 changed files with 111 additions and 108 deletions

View File

@ -6,12 +6,13 @@ import (
)
func init() {
var cmdName string = "help"
fs := flag.NewFlagSet(cmdName, flag.ExitOnError)
RegisterCommand("help", Command{
Func: HelpCmd,
Flags: func() *flag.FlagSet {
fs := flag.NewFlagSet("help", flag.ExitOnError)
RegisterCommand(cmdName, Command{
Func: HelpCmd,
Flags: fs,
return fs
}(),
Use: "<command>",
Short: "Show help for a command",
})

View File

@ -5,14 +5,16 @@ import (
)
func init() {
var cmdName string = "ls"
fs := flag.NewFlagSet(cmdName, flag.ExitOnError)
selector := fs.String("selector", defaultSelector, "Set the selector")
fs.StringVar(selector, "s", defaultSelector, "Set the selector")
RegisterCommand("ls", Command{
Func: LsCmd,
Flags: func() *flag.FlagSet {
fs := flag.NewFlagSet("ls", flag.ExitOnError)
RegisterCommand(cmdName, Command{
Func: LsCmd,
Flags: fs,
selector := fs.String("selector", defaultSelector, "Set the selector")
fs.StringVar(selector, "s", defaultSelector, "Set the selector")
return fs
}(),
Use: "[--selector=<selector>]",
Short: "List the lights",
})

View File

@ -7,19 +7,19 @@ import (
)
func init() {
var cmdName string = "poweroff"
RegisterCommand("poweroff", Command{
Func: PoweroffCmd,
Flags: func() *flag.FlagSet {
fs := flag.NewFlagSet("poweroff", flag.ExitOnError)
fs := flag.NewFlagSet(cmdName, flag.ExitOnError)
duration := fs.Float64("duration", defaultDuration, "Set the duration")
fs.Float64Var(duration, "d", defaultDuration, "Set the duration")
duration := fs.Float64("duration", defaultDuration, "Set the duration")
fs.Float64Var(duration, "d", defaultDuration, "Set the duration")
selector := fs.String("selector", defaultSelector, "Set the selector")
fs.StringVar(selector, "s", defaultSelector, "Set the selector")
selector := fs.String("selector", defaultSelector, "Set the selector")
fs.StringVar(selector, "s", defaultSelector, "Set the selector")
RegisterCommand(cmdName, Command{
Func: PoweroffCmd,
Flags: fs,
return fs
}(),
Use: "[--selector <selector>] [--duration <sec>]",
Short: "Power on",
})

View File

@ -7,19 +7,19 @@ import (
)
func init() {
var cmdName string = "poweron"
RegisterCommand("poweron", Command{
Func: PoweronCmd,
Flags: func() *flag.FlagSet {
fs := flag.NewFlagSet("poweron", flag.ExitOnError)
fs := flag.NewFlagSet(cmdName, flag.ExitOnError)
duration := fs.Float64("duration", defaultDuration, "Set the duration")
fs.Float64Var(duration, "d", defaultDuration, "Set the duration")
duration := fs.Float64("duration", defaultDuration, "Set the duration")
fs.Float64Var(duration, "d", defaultDuration, "Set the duration")
selector := fs.String("selector", defaultSelector, "Set the selector")
fs.StringVar(selector, "s", defaultSelector, "Set the selector")
selector := fs.String("selector", defaultSelector, "Set the selector")
fs.StringVar(selector, "s", defaultSelector, "Set the selector")
RegisterCommand(cmdName, Command{
Func: PoweronCmd,
Flags: fs,
return fs
}(),
Use: "[--selector <selector>] [--duration <sec>]",
Short: "Power on",
})

View File

@ -9,40 +9,40 @@ import (
)
func init() {
var cmdName string = "set-color"
RegisterCommand("set-color", Command{
Func: SetColorCmd,
Flags: func() *flag.FlagSet {
fs := flag.NewFlagSet("set-color", flag.ExitOnError)
fs := flag.NewFlagSet(cmdName, flag.ExitOnError)
selector := fs.String("selector", "all", "the selector")
fs.StringVar(selector, "s", "all", "the selector")
selector := fs.String("selector", "all", "the selector")
fs.StringVar(selector, "s", "all", "the selector")
power := fs.String("power", defaultPower, "power state")
fs.StringVar(power, "p", defaultPower, "power state")
power := fs.String("power", defaultPower, "power state")
fs.StringVar(power, "p", defaultPower, "power state")
hue := fs.String("hue", defaultHue, "hue level")
fs.StringVar(hue, "H", defaultHue, "hue level")
hue := fs.String("hue", defaultHue, "hue level")
fs.StringVar(hue, "H", defaultHue, "hue level")
saturation := fs.String("saturation", defaultSaturation, "saturation level")
fs.StringVar(saturation, "S", defaultSaturation, "saturation level")
saturation := fs.String("saturation", defaultSaturation, "saturation level")
fs.StringVar(saturation, "S", defaultSaturation, "saturation level")
rgb := fs.String("rgb", defaultRGB, "RGB value")
fs.StringVar(rgb, "r", defaultRGB, "RGB value")
rgb := fs.String("rgb", defaultRGB, "RGB value")
fs.StringVar(rgb, "r", defaultRGB, "RGB value")
name := fs.String("name", defaultName, "named color")
fs.StringVar(name, "n", defaultName, "named color")
name := fs.String("name", defaultName, "named color")
fs.StringVar(name, "n", defaultName, "named color")
brightness := fs.String("brightness", defaultBrightness, "brightness state")
fs.StringVar(brightness, "b", defaultBrightness, "brightness state")
brightness := fs.String("brightness", defaultBrightness, "brightness state")
fs.StringVar(brightness, "b", defaultBrightness, "brightness state")
duration := fs.Float64("duration", defaultDuration, "duration state")
fs.Float64Var(duration, "d", defaultDuration, "duration state")
duration := fs.Float64("duration", defaultDuration, "duration state")
fs.Float64Var(duration, "d", defaultDuration, "duration state")
fast := fs.Bool("fast", defaultFast, "fast state")
fs.BoolVar(fast, "f", defaultFast, "fast state")
fast := fs.Bool("fast", defaultFast, "fast state")
fs.BoolVar(fast, "f", defaultFast, "fast state")
RegisterCommand(cmdName, Command{
Func: SetColorCmd,
Flags: fs,
return fs
}(),
Use: "[--selector <selector>] [--power (on|off)] [--hue <hue>] [--saturation <saturation>] [--rgb <rbg>] [--name <color>] [--brightness <brightness>] [--duration <sec>] [--fast]",
Short: "Set the color",
})

View File

@ -7,34 +7,34 @@ import (
)
func init() {
var cmdName string = "set-state"
RegisterCommand("set-state", Command{
Func: SetStateCmd,
Flags: func() *flag.FlagSet {
fs := flag.NewFlagSet("set-state", flag.ExitOnError)
fs := flag.NewFlagSet(cmdName, flag.ExitOnError)
selector := fs.String("selector", defaultSelector, "Set the selector")
fs.StringVar(selector, "s", defaultSelector, "Set the selector")
selector := fs.String("selector", defaultSelector, "Set the selector")
fs.StringVar(selector, "s", defaultSelector, "Set the selector")
power := fs.String("power", defaultPower, "power state")
fs.StringVar(power, "p", defaultPower, "power state")
power := fs.String("power", defaultPower, "power state")
fs.StringVar(power, "p", defaultPower, "power state")
color := fs.String("color", defaultColor, "color state")
fs.StringVar(color, "c", defaultColor, "color state")
color := fs.String("color", defaultColor, "color state")
fs.StringVar(color, "c", defaultColor, "color state")
brightness := fs.String("brightness", defaultBrightness, "brightness state")
fs.StringVar(brightness, "b", defaultBrightness, "brightness state")
brightness := fs.String("brightness", defaultBrightness, "brightness state")
fs.StringVar(brightness, "b", defaultBrightness, "brightness state")
duration := fs.Float64("duration", defaultDuration, "duration state")
fs.Float64Var(duration, "d", defaultDuration, "duration state")
duration := fs.Float64("duration", defaultDuration, "duration state")
fs.Float64Var(duration, "d", defaultDuration, "duration state")
infrared := fs.String("infrared", defaultInfrared, "infrared state")
fs.StringVar(infrared, "i", defaultInfrared, "infrared state")
infrared := fs.String("infrared", defaultInfrared, "infrared state")
fs.StringVar(infrared, "i", defaultInfrared, "infrared state")
fast := fs.Bool("fast", defaultFast, "fast state")
fs.BoolVar(fast, "f", defaultFast, "fast state")
fast := fs.Bool("fast", defaultFast, "fast state")
fs.BoolVar(fast, "f", defaultFast, "fast state")
RegisterCommand(cmdName, Command{
Func: SetStateCmd,
Flags: fs,
return fs
}(),
Use: "[--selector <selector>] [--power (on|off)] [--color <color>] [--brightness <brightness>] [--duration <sec>] [--infrared <infrared>] [--fast]",
Short: "Set various state attributes",
})

View File

@ -7,37 +7,37 @@ import (
)
func init() {
var cmdName string = "set-white"
RegisterCommand("set-white", Command{
Func: SetWhiteCmd,
Flags: func() *flag.FlagSet {
fs := flag.NewFlagSet("set-white", flag.ExitOnError)
fs := flag.NewFlagSet(cmdName, flag.ExitOnError)
selector := fs.String("selector", "all", "the selector")
fs.StringVar(selector, "s", "all", "the selector")
selector := fs.String("selector", "all", "the selector")
fs.StringVar(selector, "s", "all", "the selector")
power := fs.String("power", defaultPower, "power state")
fs.StringVar(power, "p", defaultPower, "power state")
power := fs.String("power", defaultPower, "power state")
fs.StringVar(power, "p", defaultPower, "power state")
kelvin := fs.String("kelvin", defaultWhiteKelvin, "kelvin level")
fs.StringVar(kelvin, "k", defaultWhiteKelvin, "kelvin level")
kelvin := fs.String("kelvin", defaultWhiteKelvin, "kelvin level")
fs.StringVar(kelvin, "k", defaultWhiteKelvin, "kelvin level")
name := fs.String("name", defaultWhiteName, "named white level")
fs.StringVar(name, "n", defaultWhiteName, "named white level")
name := fs.String("name", defaultWhiteName, "named white level")
fs.StringVar(name, "n", defaultWhiteName, "named white level")
brightness := fs.String("brightness", defaultBrightness, "brightness state")
fs.StringVar(brightness, "b", defaultBrightness, "brightness state")
brightness := fs.String("brightness", defaultBrightness, "brightness state")
fs.StringVar(brightness, "b", defaultBrightness, "brightness state")
duration := fs.Float64("duration", defaultDuration, "duration state")
fs.Float64Var(duration, "d", defaultDuration, "duration state")
duration := fs.Float64("duration", defaultDuration, "duration state")
fs.Float64Var(duration, "d", defaultDuration, "duration state")
infrared := fs.String("infrared", defaultInfrared, "infrared state")
fs.StringVar(infrared, "i", defaultInfrared, "infrared state")
infrared := fs.String("infrared", defaultInfrared, "infrared state")
fs.StringVar(infrared, "i", defaultInfrared, "infrared state")
fast := fs.Bool("fast", defaultFast, "fast state")
fs.BoolVar(fast, "f", defaultFast, "fast state")
fast := fs.Bool("fast", defaultFast, "fast state")
fs.BoolVar(fast, "f", defaultFast, "fast state")
RegisterCommand(cmdName, Command{
Func: SetWhiteCmd,
Flags: fs,
return fs
}(),
Use: "[--selector <selector>] [--power (on|off)] [--kelvin <kelvin>] [--name <color>] [--brightness <brightness>] [--duration <sec>] [--infrared] [--fast]",
Short: "Set the white level",
})

View File

@ -5,19 +5,19 @@ import (
)
func init() {
var cmdName string = "toggle"
RegisterCommand("toggle", Command{
Func: ToggleCmd,
Flags: func() *flag.FlagSet {
fs := flag.NewFlagSet("toggle", flag.ExitOnError)
fs := flag.NewFlagSet(cmdName, flag.ExitOnError)
duration := fs.Float64("duration", defaultDuration, "Set the duration")
fs.Float64Var(duration, "d", defaultDuration, "Set the duration")
duration := fs.Float64("duration", defaultDuration, "Set the duration")
fs.Float64Var(duration, "d", defaultDuration, "Set the duration")
selector := fs.String("selector", defaultSelector, "Set the selector")
fs.StringVar(selector, "s", defaultSelector, "Set the selector")
selector := fs.String("selector", defaultSelector, "Set the selector")
fs.StringVar(selector, "s", defaultSelector, "Set the selector")
RegisterCommand(cmdName, Command{
Func: ToggleCmd,
Flags: fs,
return fs
}(),
Use: "[--selector <selector>] [--duration <sec>]",
Short: "Toggle the power on/off",
})