Fix merge conflicts in toc tree.
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Edward G · committed by Edward G · parent 5961d31 · Browse files · 2 files·+96 added−119 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+96 added−119 removed
- other:+96 added−119 removed
Provenance
- Commit
76db878- Tree
68770c4- Author
Edward G <edward.g2013@gmail.com>- Committer
Edward G <edward.g2013@gmail.com>- Parent
5961d31
2 files changed+96 added−119 removed
modified:docs/documentation.rst+93 added-118 removed
1-Documenting Scripts1+Help Pages2 ===================3 4 .. currentmodule:: click5 6-Click makes it very easy to document your command line tools. First of7-all, it automatically generates help pages for you. While these are8-currently not customizable in terms of their layout, all of the text9-can be changed.6+Click makes it very easy to document your command line tools. For most things Click automatically generates help pages for you. By design the text is customizable, but the layout is not.7 8 Help Texts9 ----------10 14-Commands and options accept help arguments. In the case of commands, the15-docstring of the function is automatically used if provided.11+Commands and options accept help arguments. For commands, the docstring of the function is automatically used if provided.12 13 Simple example:14 15 .. click:example::16 17 @click.command()18 @click.option('--count', default=1, help='number of greetings')23- @click.argument('name')24- def hello(count, name):25- """This script prints hello NAME COUNT times."""19+ @click.option('--name', help='a name')20+ def hello(count, name=False):21+ """This script prints hello and a name one or more times."""22 for x in range(count):23+ if name:27- click.echo(f"Hello {name}!")24+ click.echo(f"Hello {name}!")25+ else:26+ click.echo("Hello!")27 29-And what it looks like:28+And from the command line:29 30 .. click:run::31 32 invoke(hello, args=['--help'])33 34 35 .. _documenting-arguments:36 37+Command Short Help38+------------------39+40+For sub commands, a short help snippet is generated. By default, it's the first sentence of the docstring. If it is too long, then it will show as much as it can on one line and end with ``...``. The short help snippet can also be overridden with the kwarg ``short_help``:41+42+.. click:example::43+44+ @click.group()45+ def cli():46+ """A simple command line tool."""47+48+ @cli.command('init', short_help='init the repo')49+ def init():50+ """Initializes the repository."""51+52+And from the command line:53+54+.. click:run::55+56+ invoke(cli, args=['--help'])57+58+Command Epilog Help59+-------------------60+61+The help epilog is printed at the end of the help and is useful for showing example command usages or referencing additional help resources.62+63+.. click:example::64+65+ @click.command(epilog='Check out our docs at https://click.palletsprojects.com/ for more details')66+ def init():67+ """Initializes the repository."""68+69+And from the command line:70+71+.. click:run::72+73+ invoke(init, args=['--help'])74+75 Documenting Arguments76 ----------------------77 41-:func:`click.argument` does not take a ``help`` parameter. This is to42-follow the general convention of Unix tools of using arguments for only43-the most necessary things, and to document them in the command help text44-by referring to them by name.78+:class:`click.argument` does not take a ``help`` parameter. This follows the Unix Command Line Tools convention of using arguments only for necessary things and documenting them in the command help text79+by name. For Python that means including them in docstrings.80 46-You might prefer to reference the argument in the description:81+A brief example:82 83 .. click:example::84 85 @click.command()1 unmodified line87 def touch(filename):88 """Print FILENAME."""89 click.echo(filename)90 56-And what it looks like:91+And from the command line:92 93 .. click:run::94 95 invoke(touch, args=['--help'])96 62-Or you might prefer to explicitly provide a description of the argument:97+Or more explicitly:98 99 .. click:example::100 101 @click.command()4 unmodified lines106 FILENAME is the name of the file to check.107 """108 click.echo(filename)109 75-And what it looks like:110+And from the command line:111 112 .. click:run::113 114 invoke(touch, args=['--help'])115 81-For more examples, see the examples in :doc:`/arguments`.116+Click's Wrapping Behavior117+----------------------------118+Click's default wrapping ignores single new lines and rewraps the text based on the width of the terminal, to a maximum of 80 characters. In the example notice how the second grouping of three lines is rewrapped into a single paragraph.119 120+.. click:example::121 84-Preventing Rewrapping85----------------------122+ @click.command()123+ def cli():124+ """125+ This is a very long paragraph and as you126+ can see wrapped very early in the source text127+ but will be rewrapped to the terminal width in128+ the final output.129 87-The default behavior of Click is to rewrap text based on the width of the88-terminal, to a maximum 80 characters. In some circumstances, this can become89-a problem. The main issue is when showing code examples, where newlines are90-significant.130+ This is131+ a paragraph132+ that is compacted.133+ """134 92-Rewrapping can be disabled on a per-paragraph basis by adding a line with93-solely the ``\b`` escape marker in it. This line will be removed from the94-help text and rewrapping will be disabled.135+And from the command line:136 137+.. click:run::138+139+ invoke(cli, args=['--help'])140+141+Escaping Click's Wrapping142+---------------------------143+Sometimes Click's wrapping can be a problem, such as when showing code examples where newlines are significant. This behavior can be escaped on a per-paragraph basis by adding a line with only ``\b`` . The ``\b`` is removed from the rendered help text.144+145 Example:146 147 .. click:example::148 149 @click.command()150 def cli():151 """First paragraph.152 104- This is a very long second paragraph and as you105- can see wrapped very early in the source text106- but will be rewrapped to the terminal width in107- the final output.108-153 \b154 This is155 a paragraph156 without rewrapping.1 unmodified line158 And this is a paragraph159 that will be rewrapped again.160 """161 118-And what it looks like:162+And from the command line:163 164 .. click:run::165 166 invoke(cli, args=['--help'])167 124-To change the maximum width, pass ``max_content_width`` when calling the command.168+To change the rendering maximum width, pass ``max_content_width`` when calling the command.169 170 .. code-block:: python171 172 cli(max_content_width=120)173 130-174 .. _doc-meta-variables:175 176 Truncating Help Texts177 ---------------------178 136-Click gets command help text from function docstrings. However if you137-already use docstrings to document function arguments you may not want138-to see :param: and :return: lines in your help text.179+Click gets :class:`Command` help text from the docstring. If you do not want to include part of the docstring, add the ``\f`` escape marker to have Click truncate the help text after the marker.180 140-You can use the ``\f`` escape marker to have Click truncate the help text141-after the marker.142-181 Example:182 183 .. click:example::184 185 @click.command()148- @click.pass_context149- def cli(ctx):186+ def cli():187 """First paragraph.151-152- This is a very long second153- paragraph and not correctly154- wrapped but it will be rewrapped.188 \f189 157- :param click.core.Context ctx: Click context.190+ Words to not be included.191 """192 160-And what it looks like:193+And from the command line:194 195 .. click:run::196 197 invoke(cli, args=['--help'])198 199 167-Meta Variables168---------------200+Placeholder Variable201+-----------------------202 170-Options and parameters accept a ``metavar`` argument that can change the171-meta variable in the help page. The default version is the parameter name172-in uppercase with underscores, but can be annotated differently if173-desired. This can be customized at all levels:203+The default placeholder variable (`meta variable <https://en.wikipedia.org/wiki/Metasyntactic_variable#IETF_Requests_for_Comments>`_) in the help pages is the parameter name in uppercase with underscores. This can be changed for Commands and Parameters with the ``options_metavar`` and ``metavar`` kwargs.204 205 .. click:example::206 207+ # This controls entry on the usage line.177- @click.command(options_metavar='<options>')208+ @click.command(options_metavar='[[options]]')209 @click.option('--count', default=1, help='number of greetings',210 metavar='<int>')211 @click.argument('name', metavar='<name>')212 def hello(count, name):182- """This script prints hello <name> <int> times."""213+ """This script prints hello to things."""214 for x in range(count):215 click.echo(f"Hello {name}!")216 217 Example:1 unmodified line219 .. click:run::220 221 invoke(hello, args=['--help'])222 192-193-Command Short Help194-------------------195-196-For commands, a short help snippet is generated. By default, it's the first197-sentence of the help message of the command, unless it's too long. This can198-also be overridden:199-200-.. click:example::201-202- @click.group()203- def cli():204- """A simple command line tool."""205-206- @cli.command('init', short_help='init the repo')207- def init():208- """Initializes the repository."""209-210- @cli.command('delete', short_help='delete the repo')211- def delete():212- """Deletes the repository."""213-214-And what it looks like:215-216-.. click:run::217-218- invoke(cli, prog_name='repo.py')219-220-Command Epilog Help221--------------------222-223-The help epilog is like the help string but it's printed at the end of the help224-page after everything else. Useful for showing example command usages or225-referencing additional help resources.226-227-.. click:example::228-229- @click.command(epilog='Check out our docs at https://click.palletsprojects.com/ for more details')230- def init():231- """Initializes the repository."""232-233-And what it looks like:234-235-.. click:run::236-237- invoke(init, prog_name='repo.py', args=['--help'])238-223 Help Parameter Customization224 ----------------------------225+The help parameter(s) is automatically added by Click for any command. The default is ``--help`` but can be override by the context setting :attr:`~Context.help_option_names`. Click also performs automatic conflict resolution on the default help parameter so if a command itself implements a parameter named ``help`` then the default help will no be run.226 242-.. versionadded:: 2.0243-244-The help parameter is implemented in Click in a very special manner.245-Unlike regular parameters it's automatically added by Click for any246-command and it performs automatic conflict resolution. By default it's247-called ``--help``, but this can be changed. If a command itself implements248-a parameter with the same name, the default help parameter stops accepting249-it. There is a context setting that can be used to override the names of250-the help parameters called :attr:`~Context.help_option_names`.251-227 This example changes the default parameters to ``-h`` and ``--help``228 instead of just ``--help``:229 230 .. click:example::3 unmodified lines234 @click.command(context_settings=CONTEXT_SETTINGS)235 def cli():236 pass237 263-And what it looks like:238+And from the command line:239 240 .. click:run::241 242 invoke(cli, ['-h'])modified:docs/index.rst+3 added-1 removed
70 unmodified lines71 entry-points72 virtualenv73 setuptools74 parameters75- options75 arguments76+ options77 commands78+ documentation79 prompts80 documentation81+ handling-files82 complex83 advanced84 testing85 utils25 unmodified lines