Commit 86bc450b authored by Matt Bell's avatar Matt Bell Committed by Juan Batiz-Benet

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

parent 97b87190
......@@ -13,7 +13,12 @@ func Parse(input []string, root *commands.Command) ([]string, []string, map[stri
return nil, nil, nil, err
}
opts, args, err := parseOptions(input, path, root)
options, err := root.GetOptions(path)
if err != nil {
return nil, nil, nil, err
}
opts, args, err := parseOptions(input, options)
if err != nil {
return nil, nil, nil, err
}
......@@ -44,12 +49,7 @@ func parsePath(input []string, root *commands.Command) ([]string, []string, erro
// 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)
if err != nil {
return nil, nil, err
}
func parseOptions(input []string, options map[string]commands.Option) (map[string]string, []string, error) {
opts := make(map[string]string)
args := make([]string, 0)
......
......@@ -15,8 +15,13 @@ func TestOptionParsing(t *testing.T) {
}
cmd.Register("test", &commands.Command{})
opts, input, err := parseOptions([]string{ "--beep", "--boop=5 lol", "test2", "-cVb", "beep" },
[]string{"test"}, cmd)
path := []string{"test"}
options, err := cmd.GetOptions(path)
if err != nil {
t.Error(err)
}
opts, input, err := parseOptions([]string{ "--beep", "--boop=5 lol", "test2", "-cVb", "beep" }, options)
/*for k, v := range opts {
fmt.Printf("%s: %s\n", k, v)
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment