store CLI defaults into variables
This commit is contained in:
parent
676eabb0cb
commit
67cd97e2d8
@ -26,6 +26,18 @@ type Command struct {
|
|||||||
|
|
||||||
var commandRegistry = make(map[string]Command)
|
var commandRegistry = make(map[string]Command)
|
||||||
|
|
||||||
|
var (
|
||||||
|
defaultSelector string = "all"
|
||||||
|
defaultDuration float64 = 1.0
|
||||||
|
defaultPower string = ""
|
||||||
|
defaultColor string = ""
|
||||||
|
defaultBrightness string = ""
|
||||||
|
defaultInfrared string = ""
|
||||||
|
defaultFast bool = false
|
||||||
|
defaultWhiteKelvin string = ""
|
||||||
|
defaultWhiteName string = ""
|
||||||
|
)
|
||||||
|
|
||||||
func (f Flags) String(name string) string {
|
func (f Flags) String(name string) string {
|
||||||
return f.FlagSet.Lookup(name).Value.String()
|
return f.FlagSet.Lookup(name).Value.String()
|
||||||
}
|
}
|
||||||
|
@ -12,8 +12,8 @@ var (
|
|||||||
func init() {
|
func init() {
|
||||||
var cmdName string = "ls"
|
var cmdName string = "ls"
|
||||||
fs := flag.NewFlagSet(cmdName, flag.ExitOnError)
|
fs := flag.NewFlagSet(cmdName, flag.ExitOnError)
|
||||||
selector := fs.String("selector", "all", "Set the selector")
|
selector := fs.String("selector", defaultSelector, "Set the selector")
|
||||||
fs.StringVar(selector, "s", "all", "Set the selector")
|
fs.StringVar(selector, "s", defaultSelector, "Set the selector")
|
||||||
|
|
||||||
RegisterCommand(cmdName, Command{
|
RegisterCommand(cmdName, Command{
|
||||||
Func: LsCmd,
|
Func: LsCmd,
|
||||||
|
@ -12,26 +12,26 @@ func init() {
|
|||||||
|
|
||||||
fs := flag.NewFlagSet(cmdName, flag.ExitOnError)
|
fs := flag.NewFlagSet(cmdName, flag.ExitOnError)
|
||||||
|
|
||||||
selector := fs.String("selector", "all", "Set the selector")
|
selector := fs.String("selector", defaultSelector, "Set the selector")
|
||||||
fs.StringVar(selector, "s", "all", "Set the selector")
|
fs.StringVar(selector, "s", defaultSelector, "Set the selector")
|
||||||
|
|
||||||
power := fs.String("power", "", "power state")
|
power := fs.String("power", defaultPower, "power state")
|
||||||
fs.StringVar(power, "p", "", "power state")
|
fs.StringVar(power, "p", defaultPower, "power state")
|
||||||
|
|
||||||
color := fs.String("color", "", "color state")
|
color := fs.String("color", defaultColor, "color state")
|
||||||
fs.StringVar(color, "c", "", "color state")
|
fs.StringVar(color, "c", defaultColor, "color state")
|
||||||
|
|
||||||
brightness := fs.String("brightness", "", "brightness state")
|
brightness := fs.String("brightness", defaultBrightness, "brightness state")
|
||||||
fs.StringVar(brightness, "b", "", "brightness state")
|
fs.StringVar(brightness, "b", defaultBrightness, "brightness state")
|
||||||
|
|
||||||
duration := fs.Float64("duration", 1.0, "duration state")
|
duration := fs.Float64("duration", defaultDuration, "duration state")
|
||||||
fs.Float64Var(duration, "d", 1.0, "duration state")
|
fs.Float64Var(duration, "d", defaultDuration, "duration state")
|
||||||
|
|
||||||
infrared := fs.String("infrared", "", "infrared state")
|
infrared := fs.String("infrared", defaultInfrared, "infrared state")
|
||||||
fs.StringVar(infrared, "i", "", "infrared state")
|
fs.StringVar(infrared, "i", defaultInfrared, "infrared state")
|
||||||
|
|
||||||
fast := fs.Bool("fast", false, "fast state")
|
fast := fs.Bool("fast", defaultFast, "fast state")
|
||||||
fs.BoolVar(fast, "f", false, "fast state")
|
fs.BoolVar(fast, "f", defaultFast, "fast state")
|
||||||
|
|
||||||
RegisterCommand(cmdName, Command{
|
RegisterCommand(cmdName, Command{
|
||||||
Func: SetStateCmd,
|
Func: SetStateCmd,
|
||||||
|
@ -15,26 +15,26 @@ func init() {
|
|||||||
selector := fs.String("selector", "all", "the selector")
|
selector := fs.String("selector", "all", "the selector")
|
||||||
fs.StringVar(selector, "s", "all", "the selector")
|
fs.StringVar(selector, "s", "all", "the selector")
|
||||||
|
|
||||||
power := fs.String("power", "", "power state")
|
power := fs.String("power", defaultPower, "power state")
|
||||||
fs.StringVar(power, "p", "", "power state")
|
fs.StringVar(power, "p", defaultPower, "power state")
|
||||||
|
|
||||||
kelvin := fs.String("kelvin", "", "kelvin level")
|
kelvin := fs.String("kelvin", defaultWhiteKelvin, "kelvin level")
|
||||||
fs.StringVar(kelvin, "k", "", "kelvin level")
|
fs.StringVar(kelvin, "k", defaultWhiteKelvin, "kelvin level")
|
||||||
|
|
||||||
name := fs.String("name", "", "named white level")
|
name := fs.String("name", defaultWhiteName, "named white level")
|
||||||
fs.StringVar(name, "n", "", "named white level")
|
fs.StringVar(name, "n", defaultWhiteName, "named white level")
|
||||||
|
|
||||||
brightness := fs.String("brightness", "", "brightness state")
|
brightness := fs.String("brightness", defaultBrightness, "brightness state")
|
||||||
fs.StringVar(brightness, "b", "", "brightness state")
|
fs.StringVar(brightness, "b", defaultBrightness, "brightness state")
|
||||||
|
|
||||||
duration := fs.Float64("duration", 1.0, "duration state")
|
duration := fs.Float64("duration", defaultDuration, "duration state")
|
||||||
fs.Float64Var(duration, "d", 1.0, "duration state")
|
fs.Float64Var(duration, "d", defaultDuration, "duration state")
|
||||||
|
|
||||||
infrared := fs.String("infrared", "", "infrared state")
|
infrared := fs.String("infrared", defaultInfrared, "infrared state")
|
||||||
fs.StringVar(infrared, "i", "", "infrared state")
|
fs.StringVar(infrared, "i", defaultInfrared, "infrared state")
|
||||||
|
|
||||||
fast := fs.Bool("fast", false, "fast state")
|
fast := fs.Bool("fast", defaultFast, "fast state")
|
||||||
fs.BoolVar(fast, "f", false, "fast state")
|
fs.BoolVar(fast, "f", defaultFast, "fast state")
|
||||||
|
|
||||||
RegisterCommand(cmdName, Command{
|
RegisterCommand(cmdName, Command{
|
||||||
Func: SetWhiteCmd,
|
Func: SetWhiteCmd,
|
||||||
|
@ -9,10 +9,12 @@ func init() {
|
|||||||
var cmdName string = "set-state"
|
var cmdName string = "set-state"
|
||||||
|
|
||||||
fs := flag.NewFlagSet(cmdName, flag.ExitOnError)
|
fs := flag.NewFlagSet(cmdName, flag.ExitOnError)
|
||||||
duration := fs.Float64("duration", 1.0, "Set the duration")
|
|
||||||
fs.Float64Var(duration, "d", 1.0, "Set the duration")
|
duration := fs.Float64("duration", defaultDuration, "Set the duration")
|
||||||
selector := fs.String("selector", "all", "Set the selector")
|
fs.Float64Var(duration, "d", defaultDuration, "Set the duration")
|
||||||
fs.StringVar(selector, "s", "all", "Set the selector")
|
|
||||||
|
selector := fs.String("selector", defaultSelector, "Set the selector")
|
||||||
|
fs.StringVar(selector, "s", defaultSelector, "Set the selector")
|
||||||
|
|
||||||
RegisterCommand(cmdName, Command{
|
RegisterCommand(cmdName, Command{
|
||||||
Func: ToggleCmd,
|
Func: ToggleCmd,
|
||||||
|
Loading…
Reference in New Issue
Block a user