提交 d1c50972 作者: Matt Bell

commands: Check for option errors when constructing Requests

上级 4af3e0ff
......@@ -46,7 +46,10 @@ func Parse(input []string, stdin *os.File, root *cmds.Command) (cmds.Request, *c
}
}
req := cmds.NewRequest(path, opts, args, cmd, optDefs)
req, err := cmds.NewRequest(path, opts, args, cmd, optDefs)
if err != nil {
return nil, cmd, path, err
}
err = cmd.CheckArguments(req)
if err != nil {
......
......@@ -94,7 +94,10 @@ func Parse(r *http.Request, root *cmds.Command) (cmds.Request, error) {
return nil, err
}
req := cmds.NewRequest(path, opts, args, cmd, optDefs)
req, err := cmds.NewRequest(path, opts, args, cmd, optDefs)
if err != nil {
return nil, err
}
err = cmd.CheckArguments(req)
if err != nil {
......
......@@ -248,12 +248,12 @@ func (r *request) ConvertOptions() error {
}
// NewEmptyRequest initializes an empty request
func NewEmptyRequest() Request {
func NewEmptyRequest() (Request, error) {
return NewRequest(nil, nil, nil, nil, nil)
}
// NewRequest returns a request initialized with given arguments
func NewRequest(path []string, opts optMap, args []interface{}, cmd *Command, optDefs map[string]Option) Request {
func NewRequest(path []string, opts optMap, args []interface{}, cmd *Command, optDefs map[string]Option) (Request, error) {
if path == nil {
path = make([]string, 0)
}
......@@ -268,7 +268,10 @@ func NewRequest(path []string, opts optMap, args []interface{}, cmd *Command, op
}
req := &request{path, opts, args, cmd, Context{}, optDefs}
req.ConvertOptions()
err := req.ConvertOptions()
if err != nil {
return nil, err
}
return req
return req, nil
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论