-
Notifications
You must be signed in to change notification settings - Fork 0
/
command.go
38 lines (34 loc) · 922 Bytes
/
command.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package gorabbit
import (
"github.com/dimonrus/gocli"
"github.com/dimonrus/porterr"
)
const (
CommandStart = "start"
CommandStop = "stop"
CommandRestart = "restart"
CommandStatus = "status"
CommandConsumer = "consumer"
CommandSet = "set"
CommandKeyWordAll = "all"
CommandKeyWordCount = "count"
)
// Parse gocli.Command
func ParseCommand(command *gocli.Command) (action string, arguments []gocli.Argument, e porterr.IError) {
args := command.Arguments()
if len(args) > 0 {
if args[0].Name != CommandConsumer {
e = porterr.New(porterr.PortErrorArgument, "Consumer command must start with keyword 'consumer'")
return
}
if len(args) < 3 {
e = porterr.New(porterr.PortErrorArgument, "Consumer command must contain action with argument")
return
}
action = args[1].Name
arguments = args[2:]
} else {
e = porterr.New(porterr.PortErrorArgument, "Consumer command is empty")
}
return
}