diff --git a/cmd/main.go b/cmd/main.go index 5de8643..40d8f29 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -20,6 +20,7 @@ func init() { RegisterCommand(NewCmdToggle()) RegisterCommand(NewCmdVersion()) RegisterCommand(NewCmdBreathe()) + RegisterCommand(NewCmdValidate()) } var Version string diff --git a/cmd/validate.go b/cmd/validate.go new file mode 100644 index 0000000..5eefb19 --- /dev/null +++ b/cmd/validate.go @@ -0,0 +1,48 @@ +package lumecmd + +import ( + "errors" + "flag" + "fmt" + + "git.kill0.net/chill9/lifx-go" +) + +func NewCmdValidate() Command { + return Command{ + Name: "validate", + Func: ValidateCmd, + Flags: func() *flag.FlagSet { + fs := flag.NewFlagSet("validate", flag.ExitOnError) + + return fs + }(), + Use: "", + Short: "Validate a color string", + } +} + +func ValidateCmd(ctx Context) (int, error) { + c := ctx.Client + + if len(ctx.Args) != 1 { + printCmdHelp(ctx.Name) + return ExitFailure, nil + } + + color := lifx.NamedColor(ctx.Args[0]) + + i, err := c.ValidateColor(color) + if err != nil { + return ExitFailure, err + } + + if validColor, ok := i.(*lifx.HSBKColor); ok { + fmt.Print(validColor) + } else { + return ExitFailure, errors.New("go type %T but wanted *HSBKColor") + } + fmt.Println() + + return ExitSuccess, nil +} diff --git a/lume.1 b/lume.1 index d4437c2..f0c5613 100644 --- a/lume.1 +++ b/lume.1 @@ -90,6 +90,10 @@ Show extended details about the lights .Op Fl Fl simple | Fl Fl table .Xc Toggle the power +.It Xo Ic validate +.Ar color_string +.Xc +Validate a color string .It Xo Ic version .Xc Print the version