test(commands/parse) take args instead of cmd for easier testing
@mappum License: MIT Signed-off-by: Brian Tiger Chow <brian@perfmode.com>
Brian Tiger Chow committed
Nov 12, 2014 at 23:44 UTC
562500491f255e7710de2f2cfe57c7670dc2f4a0
1 file changed
+4
-4
commands/cli/parse.go
+4
-4
@@ -27,7 +27,7 @@ func Parse(input []string, root *cmds.Command) (cmds.Request, *cmds.Command, []s
27
return nil, nil, path, ErrInvalidSubcmd
28
}
29
30
- args, err := parseArgs(stringArgs, cmd)
30
+ args, err := parseArgs(stringArgs, cmd.Arguments)
31
if err != nil {
32
return nil, cmd, path, err
33
}
@@ -108,10 +108,10 @@ func parseOptions(input []string) (map[string]interface{}, []string, error) {
108
return opts, args, nil
109
}
110
111
-func parseArgs(stringArgs []string, cmd *cmds.Command) ([]interface{}, error) {
111
+func parseArgs(stringArgs []string, arguments []cmds.Argument) ([]interface{}, error) {
112
// count required argument definitions
113
lenRequired := 0
114
- for _, argDef := range cmd.Arguments {
114
+ for _, argDef := range arguments {
115
if argDef.Required {
116
lenRequired++
117
}
@@ -120,7 +120,7 @@ func parseArgs(stringArgs []string, cmd *cmds.Command) ([]interface{}, error) {
120
args := make([]interface{}, len(stringArgs))
121
122
valueIndex := 0 // the index of the current stringArgs value
123
- for _, argDef := range cmd.Arguments {
123
+ for _, argDef := range arguments {
124
// skip optional argument definitions if there aren't sufficient remaining values
125
if len(stringArgs)-valueIndex <= lenRequired && !argDef.Required {
126
continue