Skip to content
Myr

Add no_args_is_help to click.Command

Before adoption: this commit came in with the history the project adopted, so no landing records it.

The functionality for no_args_is_help, available on MultiCommands, can easily be added on Commands as well. The result is not much more code, and a more consistent interface between MultiCommands and Commands. It's also nice to be able to write a click command `foo` and then just hit `foo` for help, regardless of whether its a Group or Command. closes #1156

authored by Stephen Rosen · committed by Stephen Rosen · parent a594606 · Browse files · 2 files+20 added−1 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+20 added−1 removed

  • tests:+10 added−0 removed
  • other:+10 added−1 removed

2 files+20 added−1 removed

modified:click/core.py+10 added-1 removed
783 unmodified lines
784 :param short_help: the short help to use for this command. This is785 shown on the command listing of the parent command.786 :param add_help_option: by default each command registers a ``--help``787 option. This can be disabled by this parameter.788 :param no_args_is_help: this controls what happens if no arguments are789 provided. This option is disabled by default.790 If enabled this will add ``--help`` as argument791 if no arguments are passed792 :param hidden: hide this command from help outputs.793794 :param deprecated: issues a message indicating that795 the command is deprecated.
1 unmodified line
797798 def __init__(self, name, context_settings=None, callback=None,799 params=None, help=None, epilog=None, short_help=None,800 options_metavar='[OPTIONS]', add_help_option=True,797 hidden=False, deprecated=False):801 no_args_is_help=False, hidden=False, deprecated=False):802 BaseCommand.__init__(self, name, context_settings)803 #: the callback to execute when the command fires. This might be804 #: `None` in which case nothing happens.805 self.callback = callback
9 unmodified lines
815 self.epilog = epilog816 self.options_metavar = options_metavar817 self.short_help = short_help818 self.add_help_option = add_help_option819 self.no_args_is_help = no_args_is_help820 self.hidden = hidden821 self.deprecated = deprecated822823 def get_usage(self, ctx):
112 unmodified lines
936 with formatter.indentation():937 formatter.write_text(self.epilog)938939 def parse_args(self, ctx, args):940 if not args and self.no_args_is_help and not ctx.resilient_parsing:941 echo(ctx.get_help(), color=ctx.color)942 ctx.exit()943944 parser = self.make_parser(ctx)945 opts, args, param_order = parser.parse_args(args=args)946947 for param in iter_params_for_processing(
918 unmodified lines
modified:tests/test_commands.py+10 added
66 unmodified lines
67 r'special-chars\s+Login and store the token in ~/.netrc\.\s*',68 result.output) is not None697071def test_no_args_is_help(runner):72 @click.command(no_args_is_help=True)73 def cli():74 pass7576 result = runner.invoke(cli, [])77 assert result.exit_code == 078 assert 'Show this message and exit.' in result.output798081def test_default_maps(runner):82 @click.group()83 def cli():84 pass
209 unmodified lines