Skip to content
Myr

Merge pull request #1167 from sirosen/no-args-help-command

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

Add no_args_is_help to click.Command

authored by David Lord · committed by GitHub · parents 68ecafd, 02ba36f · Browse files · 3 files+23 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

3 files+23 added−1 removed

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

3 files+23 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
modified:CHANGES.rst+3 added
5 unmodified lines
6-----------78Unreleased910- Add ``no_args_is_help`` option to ``click.Command``, defaults to False (`#1167`_)1112.. _#1167: https://github.com/pallets/click/pull/11671314Version 7.015-----------1617Released 2018-09-25
627 unmodified lines