diff --git a/cmd/help.go b/cmd/help.go index b41a31b..f5f90fb 100644 --- a/cmd/help.go +++ b/cmd/help.go @@ -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: "", Short: "Show help for a command", }) diff --git a/cmd/ls.go b/cmd/ls.go index 03a0f3b..c05bdfb 100644 --- a/cmd/ls.go +++ b/cmd/ls.go @@ -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=]", Short: "List the lights", }) diff --git a/cmd/poweroff.go b/cmd/poweroff.go index ebf81fa..f990345 100644 --- a/cmd/poweroff.go +++ b/cmd/poweroff.go @@ -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 ] [--duration ]", Short: "Power on", }) diff --git a/cmd/poweron.go b/cmd/poweron.go index 620048c..c35a520 100644 --- a/cmd/poweron.go +++ b/cmd/poweron.go @@ -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 ] [--duration ]", Short: "Power on", }) diff --git a/cmd/setcolor.go b/cmd/setcolor.go index c05bb1c..dfadce0 100644 --- a/cmd/setcolor.go +++ b/cmd/setcolor.go @@ -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 ] [--power (on|off)] [--hue ] [--saturation ] [--rgb ] [--name ] [--brightness ] [--duration ] [--fast]", Short: "Set the color", }) diff --git a/cmd/setstate.go b/cmd/setstate.go index 3e3f748..a107871 100644 --- a/cmd/setstate.go +++ b/cmd/setstate.go @@ -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 ] [--power (on|off)] [--color ] [--brightness ] [--duration ] [--infrared ] [--fast]", Short: "Set various state attributes", }) diff --git a/cmd/setwhite.go b/cmd/setwhite.go index 8498ad9..8815aa2 100644 --- a/cmd/setwhite.go +++ b/cmd/setwhite.go @@ -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 ] [--power (on|off)] [--kelvin ] [--name ] [--brightness ] [--duration ] [--infrared] [--fast]", Short: "Set the white level", }) diff --git a/cmd/toggle.go b/cmd/toggle.go index 5616b12..47c5332 100644 --- a/cmd/toggle.go +++ b/cmd/toggle.go @@ -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 ] [--duration ]", Short: "Toggle the power on/off", })