提交 968ec344 作者: Matt Bell 提交者: Juan Batiz-Benet

commands/cli: Made Parse return a Request object instead of separate values

上级 7a36278d
...@@ -7,23 +7,23 @@ import ( ...@@ -7,23 +7,23 @@ import (
"github.com/jbenet/go-ipfs/commands" "github.com/jbenet/go-ipfs/commands"
) )
func Parse(input []string, root *commands.Command) ([]string, []string, map[string]string, error) { func Parse(input []string, root *commands.Command) (*commands.Request, error) {
path, input, err := parsePath(input, root) path, input, err := parsePath(input, root)
if err != nil { if err != nil {
return nil, nil, nil, err return nil, err
} }
options, err := root.GetOptions(path) options, err := root.GetOptions(path)
if err != nil { if err != nil {
return nil, nil, nil, err return nil, err
} }
opts, args, err := parseOptions(input, options) opts, args, err := parseOptions(input, options)
if err != nil { if err != nil {
return nil, nil, nil, err return nil, err
} }
return path, args, opts, nil return commands.NewRequest(path, opts, args), nil
} }
// parsePath gets the command path from the command line input // parsePath gets the command path from the command line input
...@@ -49,8 +49,8 @@ func parsePath(input []string, root *commands.Command) ([]string, []string, erro ...@@ -49,8 +49,8 @@ func parsePath(input []string, root *commands.Command) ([]string, []string, erro
// parseOptions 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 // returns the parsed options as strings, along with the CLI args
func parseOptions(input []string, options map[string]commands.Option) (map[string]string, []string, error) { func parseOptions(input []string, options map[string]commands.Option) (map[string]interface{}, []string, error) {
opts := make(map[string]string) opts := make(map[string]interface{})
args := make([]string, 0) args := make([]string, 0)
// TODO: error if one option is defined multiple times // TODO: error if one option is defined multiple times
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论