diff --git a/commands/cli/parse.go b/commands/cli/parse.go index f766af43640331ed15d5e8e7ec118015d05c6b89..bd37419155e6ff70f6235ff2a409a0672a529574 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 2ede7b9c8120aa9fd886893fc829d7059fedc978..247ca3d1e62d6de0c3a4fbcbeb6a992d5bb431b5 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)