diff options
Diffstat (limited to 'src/rhctl/audio_switch_command.go')
-rw-r--r-- | src/rhctl/audio_switch_command.go | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/src/rhctl/audio_switch_command.go b/src/rhctl/audio_switch_command.go index e865a90..2aed51f 100644 --- a/src/rhctl/audio_switch_command.go +++ b/src/rhctl/audio_switch_command.go @@ -200,12 +200,63 @@ func SwitchCommandParseStatus(args []string) (cmdstr SwitchCmdString, cmdargs [] } return } +func SwitchCommandParseRelay(args []string) (cmdstr SwitchCmdString, cmdargs []interface{}, err error) { + if len(args) != 2 { + err = fmt.Errorf("wrong number of arguments, expecting: <oc-num> (latch|unlatch|pulse)") + return + } + var num SwitchRelayNum + if err = num.FromString(args[0]); err != nil { + return + } + cmdargs = append(cmdargs, num) + switch args[1] { + case "latch": + cmdstr = SwitchCmdRelayLatch + case "unlatch": + cmdstr = SwitchCmdRelayUnlatch + case "pulse": + cmdstr = SwitchCmdRelayPulse + default: + err = fmt.Errorf("unknown operation: '%s', must be one of latch, unlatch, pulse", args[1]) + return + } + return +} + +func SwitchCommandParseOC(args []string) (cmdstr SwitchCmdString, cmdargs []interface{}, err error) { + if len(args) != 2 { + err = fmt.Errorf("wrong number of arguments, expecting: <oc-num> (latch|unlatch|pulse)") + return + } + var num SwitchOCNum + if err = num.FromString(args[0]); err != nil { + return + } + cmdargs = append(cmdargs, num) + switch args[1] { + case "latch": + cmdstr = SwitchCmdOCLatch + case "unlatch": + cmdstr = SwitchCmdOCUnlatch + case "pulse": + cmdstr = SwitchCmdOCPulse + default: + err = fmt.Errorf("unknown operation: '%s', must be one of latch, unlatch, pulse", args[1]) + return + } + return +} func NewSwitchCommandFromStrings(cmd string, args ...string) (c *SwitchCommand, err error) { c = &SwitchCommand{} switch cmd { case "status": c.Cmd, c.Args, err = SwitchCommandParseStatus(args) + case "relay": + c.Cmd, c.Args, err = SwitchCommandParseRelay(args) + case "oc": + c.Cmd, c.Args, err = SwitchCommandParseOC(args) default: return nil, fmt.Errorf("unknown command '%s'", cmd) } |