package main import ( "flag" "github.com/dedkovd/noolite" ) func main() { channel := flag.Int("channel", -1, "Noolite adapter channel") command := flag.String("command", "", "Command") value := flag.Int("val", 0, "Set value") red := flag.Int("r", 0, "Red channel") green := flag.Int("g", 0, "Green channel") blue := flag.Int("b", 0, "Blue channel") flag.Parse() if *channel == -1 { panic("Channel was not set") } if *command == "" { panic("Command was not set") } n, err := noolite.DefaultNooliteAdapter() if err != nil { panic(err) } defer n.Close() if *command == "set" { if *value != 0 { err = n.SetBrightnesValue(*channel, *value) } else if *red != 0 || *green != 0 || *blue != 0 { err = n.SetBrightnesValues(*channel, *red, *green, *blue) } else { panic("Need some value") } } else { commands := map[string]func(int) error{ "on": n.On, "off": n.Off, "switch": n.Switch, } cmd, ok := commands[*command] if !ok { panic("Command not found") } err = cmd(*channel) } if err != nil { panic(err) } }