mirror of
https://github.com/ipfs/kubo.git
synced 2026-02-25 04:17:44 +08:00
commands/cli: Pass option definitions as an argument to parseOptions
This commit is contained in:
parent
97b8719075
commit
86bc450b20
@ -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)
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user