From 50efc53ea340a311961c2f44646da031bee480c3 Mon Sep 17 00:00:00 2001 From: Christian Pointner Date: Fri, 1 Apr 2016 01:53:47 +0200 Subject: fixed command type mapping diff --git a/src/rhctl/audio_switch_command.go b/src/rhctl/audio_switch_command.go index c90b1e4..e865a90 100644 --- a/src/rhctl/audio_switch_command.go +++ b/src/rhctl/audio_switch_command.go @@ -178,27 +178,34 @@ type SwitchCommand struct { Response chan<- interface{} } +func SwitchCommandParseStatus(args []string) (cmdstr SwitchCmdString, cmdargs []interface{}, err error) { + if len(args) == 0 { + err = fmt.Errorf("missing argument ") + return + } + switch args[0] { + case "audio": + cmdstr = SwitchCmdStatusAudio + case "gpi": + cmdstr = SwitchCmdStatusGPI + case "oc": + cmdstr = SwitchCmdStatusOC + case "relay": + cmdstr = SwitchCmdStatusRelay + case "silence": + cmdstr = SwitchCmdStatusSilence + default: + err = fmt.Errorf("unknown status-type: '%s'", args[0]) + return + } + return +} + func NewSwitchCommandFromStrings(cmd string, args ...string) (c *SwitchCommand, err error) { c = &SwitchCommand{} switch cmd { case "status": - if len(args) == 0 { - return nil, fmt.Errorf("missing argument ") - } - switch args[0] { - case "audio": - c.Cmd = SwitchCmdStatusAudio - case "gpi": - c.Cmd = SwitchCmdStatusGPI - case "oc": - c.Cmd = SwitchCmdStatusOC - case "relay": - c.Cmd = SwitchCmdStatusRelay - case "silence": - c.Cmd = SwitchCmdStatusSilence - default: - return nil, fmt.Errorf("unknown status-type: '%s'", args[0]) - } + c.Cmd, c.Args, err = SwitchCommandParseStatus(args) default: return nil, fmt.Errorf("unknown command '%s'", cmd) } diff --git a/src/rhctl/switch_control.go b/src/rhctl/switch_control.go index ca27b86..f52e9a2 100644 --- a/src/rhctl/switch_control.go +++ b/src/rhctl/switch_control.go @@ -63,6 +63,8 @@ type SwitchControl struct { func (ctrl *SwitchControl) handleCommand(cmd *Command) { switch cmd.Type { case CmdStatus: + case CmdServer: + case CmdSwitch: if len(cmd.Args) == 0 { rhl.Printf("SwitchCTRL: ignoring empty raw switch command") return @@ -74,8 +76,6 @@ func (ctrl *SwitchControl) handleCommand(cmd *Command) { } c.Response = cmd.Response ctrl.sw.Commands <- c - case CmdServer: - case CmdSwitch: } } diff --git a/src/rhctl/telnet.go b/src/rhctl/telnet.go index c4212e6..e693e70 100644 --- a/src/rhctl/telnet.go +++ b/src/rhctl/telnet.go @@ -113,7 +113,7 @@ func telnetCmdSwitch(c *telgo.Client, args []string, ctrl *SwitchControl) bool { return false } resp := make(chan interface{}) - ctrl.Commands <- &Command{Type: CmdStatus, Args: args[1:], Response: resp} + ctrl.Commands <- &Command{Type: CmdSwitch, Args: args[1:], Response: resp} r := <-resp switch r.(type) { case error: -- cgit v0.10.2