Skip to content
Myr

Added an example for help parameter customization.

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

authored by Armin Ronacher · committed by Armin Ronacher · parent 8da75f9 · Browse files · 2 files+34 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+34 added−1 removed

  • other:+34 added−1 removed

2 files+34 added−1 removed

modified:click/core.py+1 added-1 removed
167 unmodified lines
168 help_option_names = parent.help_option_names169 else:170 help_option_names = ['--help']171172 #: The name for the help options.172 #: The names for the help options.173 self.help_option_names = help_option_names174175 if token_normalize_func is None and parent is not None:176 token_normalize_func = parent.token_normalize_func
1158 unmodified lines
modified:docs/documentation.rst+33 added
1Documenting Scripts2===================34.. currentmodule:: click56Click makes it very easy to document your command line tools. First of7all, it automatically generates help pages for you. While these are8currently not customizable in layout, all of the text can be changed.9
117 unmodified lines
127128.. click:run::129130 invoke(cli, prog_name='repo.py')131132133Help Parameter Customization134----------------------------135136.. versionadded:: 2.0137138The help parameter is very special in how it's implemented in click.139Unlike regular parameters it's automatically added by click for any140command and it performs automatic conflict resolution. By default it's141called ``--help`` but this can be changed. If a command itself implements142a parameter with the same name the default help parameter stops accepting143it. There is a context setting that can be used to override the names of144the help parameters called :attr:`~Context.help_option_names`.145146This example changes the default parameters to ``-h`` and ``--help``147instad of just ``--help``:148149.. click:example::150151 CONTEXT_DEFAULTS = dict(help_option_names=['-h', '--help'])152153 @click.command(context_defaults=CONTEXT_DEFAULTS)154 def cli():155 pass156157And what it looks like:158159.. click:run::160161 invoke(cli, ['-h'])