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

This commit is contained in:
Matt Bell 2014-10-14 15:46:49 -07:00 committed by Juan Batiz-Benet
parent 97b8719075
commit 86bc450b20
2 changed files with 14 additions and 9 deletions

View File

@ -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)

View File

@ -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)
}