diff options
author | Christian Pointner <equinox@spreadspace.org> | 2016-03-31 23:53:47 (GMT) |
---|---|---|
committer | Christian Pointner <equinox@spreadspace.org> | 2016-03-31 23:53:47 (GMT) |
commit | 50efc53ea340a311961c2f44646da031bee480c3 (patch) | |
tree | 2cd53d2a1188607b470919bc329a4636832eb1df /src/rhctl/audio_switch_command.go | |
parent | 1e5596d626ebba0c150bea5804378cd35f95387e (diff) |
fixed command type mapping
Diffstat (limited to 'src/rhctl/audio_switch_command.go')
-rw-r--r-- | src/rhctl/audio_switch_command.go | 41 |
1 files changed, 24 insertions, 17 deletions
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 <status-type>") + 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 <status-type>") - } - 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) } |