summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristian Pointner <equinox@helsinki.at>2016-04-02 23:52:24 (GMT)
committerChristian Pointner <equinox@helsinki.at>2016-04-02 23:52:24 (GMT)
commit04a00559a15f3e94520c5ff26fc90f26b1a37707 (patch)
tree545a042023dfdde1ba853249f53dae113aa31619 /src
parent2f34a5e62285a3c5334c270c6111e43fc12e8dbf (diff)
telnet state command almost done
Diffstat (limited to 'src')
-rw-r--r--src/rhctl/switch_control.go1
-rw-r--r--src/rhctl/telnet.go39
2 files changed, 38 insertions, 2 deletions
diff --git a/src/rhctl/switch_control.go b/src/rhctl/switch_control.go
index 91cc161..523269f 100644
--- a/src/rhctl/switch_control.go
+++ b/src/rhctl/switch_control.go
@@ -113,6 +113,7 @@ type SwitchControl struct {
func (ctrl *SwitchControl) handleCommand(cmd *Command) {
switch cmd.Type {
case CmdState:
+ cmd.Response <- ctrl.state
case CmdServer:
case CmdSwitch:
if len(cmd.Args) == 0 {
diff --git a/src/rhctl/telnet.go b/src/rhctl/telnet.go
index de98475..e4044ef 100644
--- a/src/rhctl/telnet.go
+++ b/src/rhctl/telnet.go
@@ -22,6 +22,8 @@
package main
import (
+ "sort"
+
"github.com/spreadspace/telgo"
)
@@ -30,8 +32,41 @@ type TelnetInterface struct {
}
func telnetCmdState(c *telgo.Client, args []string, ctrl *SwitchControl) bool {
- ctrl.Commands <- &Command{Type: CmdState}
- // TODO: implement this
+ resp := make(chan interface{})
+ ctrl.Commands <- &Command{Type: CmdState, Response: resp}
+
+ r := <-resp
+ switch r.(type) {
+ case error:
+ c.Sayln("%v", r)
+ case State:
+ s := r.(State)
+ c.Sayln("Mood: %v", s.Mood)
+
+ c.Sayln("Switch:")
+ c.Sayln(" audio:") //
+ c.Sayln(" output 1: ? (silence!!)?") //
+ c.Sayln(" output 2: ? (silence!!)?") // TODO: fill this with actual data
+ c.Sayln(" relays: ?") //
+ c.Sayln(" oc: ?") //
+
+ c.Sayln("Server:")
+ var names []string
+ for n, _ := range s.Server {
+ names = append(names, n)
+ }
+ sort.Strings(names)
+ for _, name := range names {
+ if name == s.ActiveServer {
+ c.Say(" * ")
+ } else {
+ c.Say(" ")
+ }
+ c.Sayln("%s(%s): '%s'", name, s.Server[name].Health, s.Server[name].Channel)
+ }
+ default:
+ c.Sayln("invalid response of type %T: %+v", r, r)
+ }
return false
}