diff options
author | Christian Pointner <equinox@spreadspace.org> | 2016-03-31 23:44:33 (GMT) |
---|---|---|
committer | Christian Pointner <equinox@spreadspace.org> | 2016-03-31 23:44:33 (GMT) |
commit | 1e5596d626ebba0c150bea5804378cd35f95387e (patch) | |
tree | 3907cdb92ec85a516608a3798d9169dfc14da855 /src/rhctl/telnet.go | |
parent | 6af5989872635b44607657fc1c4ff80b4df20798 (diff) |
switch status commands work now
Diffstat (limited to 'src/rhctl/telnet.go')
-rw-r--r-- | src/rhctl/telnet.go | 35 |
1 files changed, 25 insertions, 10 deletions
diff --git a/src/rhctl/telnet.go b/src/rhctl/telnet.go index 4189fc8..c4212e6 100644 --- a/src/rhctl/telnet.go +++ b/src/rhctl/telnet.go @@ -29,7 +29,7 @@ type TelnetInterface struct { server *telgo.Server } -func telnetStatus(c *telgo.Client, args []string, ctrl *SwitchControl) bool { +func telnetCmdStatus(c *telgo.Client, args []string, ctrl *SwitchControl) bool { ctrl.Commands <- &Command{Type: CmdStatus} // TODO: implement this return false @@ -64,7 +64,7 @@ func telnetUpdateListener(c *telgo.Client, ctrl *SwitchControl) { } } -func telnetListen(c *telgo.Client, args []string, ctrl *SwitchControl) bool { +func telnetCmdListen(c *telgo.Client, args []string, ctrl *SwitchControl) bool { if len(args) <= 1 { c.Sayln("missing argument: <type>") return false @@ -101,15 +101,30 @@ func telnetListen(c *telgo.Client, args []string, ctrl *SwitchControl) bool { return false } -func telnetServer(c *telgo.Client, args []string, ctrl *SwitchControl) bool { +func telnetCmdServer(c *telgo.Client, args []string, ctrl *SwitchControl) bool { ctrl.Commands <- &Command{Type: CmdServer} // TODO: implement this return false } -func telnetSwitch(c *telgo.Client, args []string, ctrl *SwitchControl) bool { - ctrl.Commands <- &Command{Type: CmdSwitch} - // TODO: implement this +func telnetCmdSwitch(c *telgo.Client, args []string, ctrl *SwitchControl) bool { + if len(args) < 2 { + c.Sayln("missing switch command") + return false + } + resp := make(chan interface{}) + ctrl.Commands <- &Command{Type: CmdStatus, Args: args[1:], Response: resp} + r := <-resp + switch r.(type) { + case error: + c.Sayln("%v", r) + case SwitchResponse: + if r.(SwitchResponse).Result != SwitchOK { + c.Sayln("%v: %s", r.(SwitchResponse).Result, r.(SwitchResponse).Message) + } + default: + c.Sayln("invalid response of type %T: %+v", r, r) + } return false } @@ -179,10 +194,10 @@ func TelnetInit(conf *Config, ctrl *SwitchControl) (telnet *TelnetInterface) { telnet = &TelnetInterface{} cmdlist := make(telgo.CmdList) - cmdlist["status"] = func(c *telgo.Client, args []string) bool { return telnetStatus(c, args, ctrl) } - cmdlist["listen"] = func(c *telgo.Client, args []string) bool { return telnetListen(c, args, ctrl) } - cmdlist["server"] = func(c *telgo.Client, args []string) bool { return telnetServer(c, args, ctrl) } - cmdlist["switch"] = func(c *telgo.Client, args []string) bool { return telnetSwitch(c, args, ctrl) } + cmdlist["status"] = func(c *telgo.Client, args []string) bool { return telnetCmdStatus(c, args, ctrl) } + cmdlist["listen"] = func(c *telgo.Client, args []string) bool { return telnetCmdListen(c, args, ctrl) } + cmdlist["server"] = func(c *telgo.Client, args []string) bool { return telnetCmdServer(c, args, ctrl) } + cmdlist["switch"] = func(c *telgo.Client, args []string) bool { return telnetCmdSwitch(c, args, ctrl) } cmdlist["help"] = telnetHelp cmdlist["quit"] = telnetQuit |