@cryptotaxi247 / kubo / commits / 86bc450b2

commands/cli: Pass option definitions as an argument to parseOptions

Matt Bell committed Oct 14, 2014 at 15:46 UTC 86bc450b20b190ece2d29d39bc4a499bee38939b
2 files changed +14 -9
commands/cli/parse.go
+7 -7
@@ -13,7 +13,12 @@ func Parse(input []string, root *commands.Command) ([]string, []string, map[stri
13 return nil, nil, nil, err
14 }
15
16 - opts, args, err := parseOptions(input, path, root)
16 + options, err := root.GetOptions(path)
17 + if err != nil {
18 + return nil, nil, nil, err
19 + }
20 +
21 + opts, args, err := parseOptions(input, options)
22 if err != nil {
23 return nil, nil, nil, err
24 }
@@ -44,12 +49,7 @@ func parsePath(input []string, root *commands.Command) ([]string, []string, erro
49
50 // parseOptions parses the raw string values of the given options
51 // returns the parsed options as strings, along with the CLI args
47 -func parseOptions(input, path []string, root *commands.Command) (map[string]string, []string, error) {
48 - options, err := root.GetOptions(path)
49 - if err != nil {
50 - return nil, nil, err
51 - }
52 -
52 +func parseOptions(input []string, options map[string]commands.Option) (map[string]string, []string, error) {
53 opts := make(map[string]string)
54 args := make([]string, 0)
55
commands/cli/parse_test.go
+7 -2
@@ -15,8 +15,13 @@ func TestOptionParsing(t *testing.T) {
15 }
16 cmd.Register("test", &commands.Command{})
17
18 - opts, input, err := parseOptions([]string{ "--beep", "--boop=5 lol", "test2", "-cVb", "beep" },
19 - []string{"test"}, cmd)
18 + path := []string{"test"}
19 + options, err := cmd.GetOptions(path)
20 + if err != nil {
21 + t.Error(err)
22 + }
23 +
24 + opts, input, err := parseOptions([]string{ "--beep", "--boop=5 lol", "test2", "-cVb", "beep" }, options)
25 /*for k, v := range opts {
26 fmt.Printf("%s: %s\n", k, v)
27 }