noolite-cli.go 692 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. package main
  2. import (
  3. "flag"
  4. "fmt"
  5. "github.com/dedkovd/noolite"
  6. )
  7. func main() {
  8. channel := flag.Int("channel", -1, "Noolite adapter channel")
  9. command := flag.String("command", "", "Command")
  10. flag.Parse()
  11. fmt.Println(*channel)
  12. fmt.Println(*command)
  13. if *channel == -1 {
  14. panic ("Channel was not set")
  15. }
  16. if *command == "" {
  17. panic("Command was not set")
  18. }
  19. n, err := noolite.DefaultNooliteAdapter()
  20. commands := map[string]func(int) error{
  21. "on": n.On,
  22. "off": n.Off,
  23. "switch": n.Switch,
  24. }
  25. if err != nil {
  26. panic(err)
  27. }
  28. defer n.Close()
  29. cmd, ok := commands[*command]
  30. if !ok {
  31. panic("Command not found")
  32. }
  33. cmd(*channel)
  34. if err != nil {
  35. panic(err)
  36. }
  37. }