Skip to content

Commit e77d5b8

Browse files
Invoke OnUsageError when missing required flags
In case of missing required flags, the OnUsageError function will now be invoked instead of directly returning the error.
1 parent eac452b commit e77d5b8

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

command_run.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,11 @@ func (cmd *Command) run(ctx context.Context, osArgs []string) (_ context.Context
314314

315315
if err := cmd.checkAllRequiredFlags(); err != nil {
316316
cmd.isInError = true
317-
_ = ShowSubcommandHelp(cmd)
317+
if cmd.OnUsageError != nil {
318+
err = cmd.OnUsageError(ctx, cmd, err, cmd.parent != nil)
319+
} else {
320+
_ = ShowSubcommandHelp(cmd)
321+
}
318322
return ctx, err
319323
}
320324

0 commit comments

Comments
 (0)