From 97b8719075bc5c3f568cca8fd8f74af3d0939197 Mon Sep 17 00:00:00 2001 From: Matt Bell <mappum@gmail.com> Date: Tue, 14 Oct 2014 15:37:05 -0700 Subject: [PATCH] commands/cli: Removed parser string handling since the go runtime handles it for us automatically --- commands/cli/parse.go | 36 ++---------------------------------- commands/cli/parse_test.go | 2 +- 2 files changed, 3 insertions(+), 35 deletions(-) diff --git a/commands/cli/parse.go b/commands/cli/parse.go index f766af436..bd3741915 100644 --- a/commands/cli/parse.go +++ b/commands/cli/parse.go @@ -21,8 +21,7 @@ func Parse(input []string, root *commands.Command) ([]string, []string, map[stri return path, args, opts, nil } - -// path gets the command path from the command line input +// parsePath gets the command path from the command line input func parsePath(input []string, root *commands.Command) ([]string, []string, error) { cmd := root i := 0 @@ -43,7 +42,7 @@ func parsePath(input []string, root *commands.Command) ([]string, []string, erro return input[:i], input[i:], nil } -// options parses the raw string values of the given options +// parseOptions parses the raw string values of the given options // returns the parsed options as strings, along with the CLI args func parseOptions(input, path []string, root *commands.Command) (map[string]string, []string, error) { options, err := root.GetOptions(path) @@ -69,37 +68,6 @@ func parseOptions(input, path []string, root *commands.Command) (map[string]stri value = split[1] } - if strings.Contains(name, "-") { - return nil, nil, fmt.Errorf("Invalid option blob: '%s' (Shouldn't contain '-')", input[i]) - } - - if value != "" && strings.Contains(value, "\"") { - // TODO: ignore escaped quotations (--foo="\"") - if !strings.HasPrefix(value, "\"") { - return nil, nil, fmt.Errorf("Invalid option blob: '%s' (Quotation wasn't at the start of value)", input[i]) - } - - value = value[1:] - - for { - if strings.HasSuffix(value, "\"") { - value = value[:len(value)-1] - break - } - - i++ - if i >= len(input) { - return nil, nil, fmt.Errorf("Unterminated string: '%s'", value) - } - - value += " " + input[i] - } - - if strings.Contains(value, "\"") { - return nil, nil, fmt.Errorf("Invalid option blob: '%s' (Value contains unescaped quotation)", value) - } - } - opts[name] = value } else if strings.HasPrefix(blob, "-") { diff --git a/commands/cli/parse_test.go b/commands/cli/parse_test.go index 2ede7b9c8..247ca3d1e 100644 --- a/commands/cli/parse_test.go +++ b/commands/cli/parse_test.go @@ -15,7 +15,7 @@ func TestOptionParsing(t *testing.T) { } cmd.Register("test", &commands.Command{}) - opts, input, err := parseOptions([]string{ "--beep", "--boop=\"5", "lol\"", "test2", "-cVb", "beep" }, + opts, input, err := parseOptions([]string{ "--beep", "--boop=5 lol", "test2", "-cVb", "beep" }, []string{"test"}, cmd) /*for k, v := range opts { fmt.Printf("%s: %s\n", k, v) -- GitLab