Add a command for validateColor API
This commit is contained in:
parent
8133953bb1
commit
23210af0c3
@ -20,6 +20,7 @@ func init() {
|
||||
RegisterCommand(NewCmdToggle())
|
||||
RegisterCommand(NewCmdVersion())
|
||||
RegisterCommand(NewCmdBreathe())
|
||||
RegisterCommand(NewCmdValidate())
|
||||
}
|
||||
|
||||
var Version string
|
||||
|
48
cmd/validate.go
Normal file
48
cmd/validate.go
Normal file
@ -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: "<command>",
|
||||
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
|
||||
}
|
Loading…
Reference in New Issue
Block a user