-
-
Notifications
You must be signed in to change notification settings - Fork 771
🐛 Ensure exit code 0 when no_args_is_help
shows help
#1240
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
e5a061f
3c9af42
f6dce2a
74f4fce
0256945
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -208,7 +208,19 @@ def _main( | |
raise click.Abort() from e | ||
except KeyboardInterrupt as e: | ||
raise click.exceptions.Exit(130) from e | ||
# TODO: When deprecating Click < 8.2 uncomment the next two lines | ||
# except click.exceptions.NoArgsIsHelpError as e: | ||
# raise click.exceptions.Exit(0) from e | ||
except click.ClickException as e: | ||
# TODO: When deprecating Click < 8.2 remove this section [start] | ||
_no_args_is_help_error = getattr( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Rather than probing attrs and instance, I suggest using the exception we want to catch. from click.exceptions import NoArgsIsHelpError and then here simply the code to be ...
except KeyboardInterrupt as e:
raise click.exceptions.Exit(130) from e
except NoArgsIsHelpError as e:
raise click.exceptions.Exit(0) from e
except click.ClickException as e:
... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To continue supporting older versions of click (which don't define the exception), the exception clause can be made conditional with code like: CatchClickNoArgsIsHelpError: Exception|tuple[()]
try:
# click >= 8.2.0
CatchClickNoArgsIsHelpError = click.exceptions.NoArgsIsHelpError
except AttributeError:
# click < 8.2.0
CatchClickNoArgsIsHelpError = () And then: except CatchClickNoArgsIsHelpError as e:
raise click.exceptions.Exit(0) from e Empty tuples are permitted in except clauses, and mean that the clause will never actually trigger at runtime. |
||
click.exceptions, "NoArgsIsHelpError", None | ||
) | ||
if _no_args_is_help_error is not None and isinstance( | ||
e, _no_args_is_help_error | ||
): | ||
raise click.exceptions.Exit(0) from e | ||
# TODO: When deprecating Click < 8.2 remove this section [end] | ||
if not standalone_mode: | ||
raise | ||
# Typer override | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would also be good to add a
assert not result.stderr
to ensure the doubled output isn't displayed