提交 db361d94 作者: Matt Bell 提交者: Juan Batiz-Benet

commands/cli: Made Parse return an error if request has unrecognized options

上级 120ead26
...@@ -71,7 +71,7 @@ func main() { ...@@ -71,7 +71,7 @@ func main() {
// BEFORE handling the parse error, if we have enough information // BEFORE handling the parse error, if we have enough information
// AND the user requested help, print it out and exit // AND the user requested help, print it out and exit
if invoc.cmd != nil { if invoc.req != nil {
longH, shortH, err := invoc.requestedHelp() longH, shortH, err := invoc.requestedHelp()
if err != nil { if err != nil {
printErr(err) printErr(err)
......
...@@ -37,6 +37,14 @@ func Parse(input []string, root *cmds.Command) (cmds.Request, *cmds.Command, []s ...@@ -37,6 +37,14 @@ func Parse(input []string, root *cmds.Command) (cmds.Request, *cmds.Command, []s
return nil, cmd, path, err return nil, cmd, path, err
} }
// check to make sure there aren't any undefined options
for k := range opts {
if _, found := optDefs[k]; !found {
err = fmt.Errorf("Unrecognized option: -%s", k)
return nil, cmd, path, err
}
}
req := cmds.NewRequest(path, opts, args, cmd, optDefs) req := cmds.NewRequest(path, opts, args, cmd, optDefs)
err = cmd.CheckArguments(req) err = cmd.CheckArguments(req)
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论