From 562500491f255e7710de2f2cfe57c7670dc2f4a0 Mon Sep 17 00:00:00 2001 From: Brian Tiger Chow Date: Wed, 12 Nov 2014 23:44:16 -0800 Subject: [PATCH] test(commands/parse) take args instead of cmd for easier testing @mappum License: MIT Signed-off-by: Brian Tiger Chow --- commands/cli/parse.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/commands/cli/parse.go b/commands/cli/parse.go index db1d13403..803d19d79 100644 --- a/commands/cli/parse.go +++ b/commands/cli/parse.go @@ -27,7 +27,7 @@ func Parse(input []string, root *cmds.Command) (cmds.Request, *cmds.Command, []s return nil, nil, path, ErrInvalidSubcmd } - args, err := parseArgs(stringArgs, cmd) + args, err := parseArgs(stringArgs, cmd.Arguments) if err != nil { return nil, cmd, path, err } @@ -108,10 +108,10 @@ func parseOptions(input []string) (map[string]interface{}, []string, error) { return opts, args, nil } -func parseArgs(stringArgs []string, cmd *cmds.Command) ([]interface{}, error) { +func parseArgs(stringArgs []string, arguments []cmds.Argument) ([]interface{}, error) { // count required argument definitions lenRequired := 0 - for _, argDef := range cmd.Arguments { + for _, argDef := range arguments { if argDef.Required { lenRequired++ } @@ -120,7 +120,7 @@ func parseArgs(stringArgs []string, cmd *cmds.Command) ([]interface{}, error) { args := make([]interface{}, len(stringArgs)) valueIndex := 0 // the index of the current stringArgs value - for _, argDef := range cmd.Arguments { + for _, argDef := range arguments { // skip optional argument definitions if there aren't sufficient remaining values if len(stringArgs)-valueIndex <= lenRequired && !argDef.Required { continue