Do not run parent node on missing child err with usageOnMissing option

Refactors usageOnMissing option to not run parent commands after
printing usage when a child node is missing.

Signed-off-by: hasheddan <georgedanielmangum@gmail.com>
This commit is contained in:
hasheddan
2020-10-04 19:27:12 -05:00
committed by Alec Thomas
parent 5b3fd5476a
commit a062611ecf
3 changed files with 40 additions and 12 deletions
+4 -1
View File
@@ -219,7 +219,10 @@ func (k *Kong) Parse(args []string) (ctx *Context, err error) {
return nil, &ParseError{error: err, Context: ctx}
}
if err = ctx.Validate(); err != nil {
return nil, &ParseError{error: err, Context: ctx}
if !k.usageOnError || !isMissingChildError(err) {
return nil, &ParseError{error: err, Context: ctx}
}
ctx.Error = err
}
if err = k.applyHook(ctx, "AfterApply"); err != nil {
return nil, &ParseError{error: err, Context: ctx}