Files
noolite-web/noolite-cli.go
2016-06-26 15:55:03 +05:00

51 lines
692 B
Go

package main
import (
"flag"
"fmt"
"github.com/dedkovd/noolite"
)
func main() {
channel := flag.Int("channel", -1, "Noolite adapter channel")
command := flag.String("command", "", "Command")
flag.Parse()
fmt.Println(*channel)
fmt.Println(*command)
if *channel == -1 {
panic ("Channel was not set")
}
if *command == "" {
panic("Command was not set")
}
n, err := noolite.DefaultNooliteAdapter()
commands := map[string]func(int) error{
"on": n.On,
"off": n.Off,
"switch": n.Switch,
}
if err != nil {
panic(err)
}
defer n.Close()
cmd, ok := commands[*command]
if !ok {
panic("Command not found")
}
cmd(*channel)
if err != nil {
panic(err)
}
}