| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 |
- 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)
- }
- }
|