Skip to content
Myr

documentation.rst

This file

Path

docs/documentation.rst

162 lines · 4.2 KiB

Last changed by

Merge pull request #153 from iKevinY/click-renameArmin Ronacherbefore adoption327cfde

History of this file

Take it

The walk stopped after 200 commits: lines older than 469ba25 point at it.

Implemented atomic file opening support.Armin Ronacherbefore adoption469ba25

lines 1–3why, one step back
1Documenting Scripts
2===================3

Added an example for help parameter customization.Armin Ronacherbefore adoption6e98e9b

lines 4–5why, one step back
4.. currentmodule:: click
5

Implemented atomic file opening support.Armin Ronacherbefore adoption469ba25

line 6why, one step back
6Click makes it very easy to document your command line tools. First of

Merge pull request #109 from iKevinY/doc-fixesArmin Ronacherbefore adoptiond428e69

line 7why, one step back
7all, it automatically generates help pages for you. While these are

Merge pull request #125 from iKevinY/doc-fixesArmin Ronacherbefore adoption1d25afd

lines 8–9why, one step back
8currently not customizable in terms of their layout, all of the text
9can be changed.

Implemented atomic file opening support.Armin Ronacherbefore adoption469ba25

lines 10–13why, one step back
10
11Help Texts12----------13

Merge pull request #125 from iKevinY/doc-fixesArmin Ronacherbefore adoption1d25afd

lines 14–15why, one step back
14Commands and options accept help arguments. In the case of commands, the
15docstring of the function is automatically used if provided.

Implemented atomic file opening support.Armin Ronacherbefore adoption469ba25

lines 16–34why, one step back
16
17Simple example:1819.. click:example::2021 @click.command()22 @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."""26 for x in range(count):27 click.echo('Hello %s!' % name)2829And what it looks like:3031.. click:run::3233 invoke(hello, args=['--help'])34

Documentation fixesKevin Yapbefore adoption67523af

lines 35–36why, one step back
35Arguments cannot be documented this way. This is to follow the general
36convention of Unix tools of using arguments for only the most necessary

Implemented atomic file opening support.Armin Ronacherbefore adoption469ba25

lines 37–42why, one step back
37things and to document them in the introduction text by referring to them
38by name.3940Preventing Rewrapping41---------------------42

Merge pull request #153 from iKevinY/click-renameArmin Ronacherbefore adoption327cfde

line 43why, one step back
43The default behavior of Click is to rewrap text based on the width of the

Merge pull request #125 from iKevinY/doc-fixesArmin Ronacherbefore adoption1d25afd

lines 44–45why, one step back
44terminal. In some circumstances, this can become a problem. The main issue
45is when showing code examples, where newlines are significant.

Implemented atomic file opening support.Armin Ronacherbefore adoption469ba25

line 46why, one step back
46

Merge pull request #109 from iKevinY/doc-fixesArmin Ronacherbefore adoptiond428e69

lines 47–48why, one step back
47Rewrapping can be disabled on a per-paragraph basis by adding a line with
48solely the ``\b`` escape marker in it. This line will be removed from the

Implemented atomic file opening support.Armin Ronacherbefore adoption469ba25

lines 49–79why, one step back
49help text and rewrapping will be disabled.
5051Example:5253.. click:example::5455 @click.command()56 def cli():57 """First paragraph.5859 This is a very long second paragraph and as you60 can see wrapped very early in the source text61 but will be rewrapped to the terminal width in62 the final output.6364 \b65 This is66 a paragraph67 without rewrapping.6869 And this is a paragraph70 that will be rewrapped again.71 """7273And what it looks like:7475.. click:run::7677 invoke(cli, args=['--help'])7879

Merge pull request #109 from iKevinY/doc-fixesArmin Ronacherbefore adoptiond428e69

lines 80–81why, one step back
80Meta Variables
81--------------

Implemented atomic file opening support.Armin Ronacherbefore adoption469ba25

lines 82–84why, one step back
82
83Options and parameters accept a ``metavar`` argument that can change the84meta variable in the help page. The default version is the parameter name

Merge pull request #109 from iKevinY/doc-fixesArmin Ronacherbefore adoptiond428e69

lines 85–86why, one step back
85in uppercase with underscores, but can be annotated differently if
86desired. This can be customized at all levels:

Implemented atomic file opening support.Armin Ronacherbefore adoption469ba25

lines 87–104why, one step back
87
88.. click:example::8990 @click.command(options_metavar='<options>')91 @click.option('--count', default=1, help='number of greetings',92 metavar='<int>')93 @click.argument('name', metavar='<name>')94 def hello(count, name):95 """This script prints hello <name> <int> times."""96 for x in range(count):97 click.echo('Hello %s!' % name)9899Example:100101.. click:run::102103 invoke(hello, args=['--help'])104

Merge pull request #109 from iKevinY/doc-fixesArmin Ronacherbefore adoptiond428e69

line 105why, one step back
105

Implemented atomic file opening support.Armin Ronacherbefore adoption469ba25

lines 106–108why, one step back
106Command Short Help
107------------------108

Merge pull request #109 from iKevinY/doc-fixesArmin Ronacherbefore adoptiond428e69

lines 109–111why, one step back
109For commands, a short help snippet is generated. By default, it's the first
110sentence of the help message of the command, unless it's too long. This can111also be overridden:

Implemented atomic file opening support.Armin Ronacherbefore adoption469ba25

lines 112–131why, one step back
112
113.. click:example::114115 @click.group()116 def cli():117 """A simple command line tool."""118119 @cli.command('init', short_help='init the repo')120 def init():121 """Initializes the repository."""122123 @cli.command('delete', short_help='delete the repo')124 def delete():125 """Deletes the repository."""126127And what it looks like:128129.. click:run::130131 invoke(cli, prog_name='repo.py')

Added an example for help parameter customization.Armin Ronacherbefore adoption6e98e9b

lines 132–138why, one step back
132
133134Help Parameter Customization135----------------------------136137.. versionadded:: 2.0138

Merge pull request #153 from iKevinY/click-renameArmin Ronacherbefore adoption327cfde

lines 139–140why, one step back
139The help parameter is implemented in Click in a very special manner.
140Unlike regular parameters it's automatically added by Click for any

Added an example for help parameter customization.Armin Ronacherbefore adoption6e98e9b

line 141why, one step back
141command and it performs automatic conflict resolution. By default it's

Merge pull request #125 from iKevinY/doc-fixesArmin Ronacherbefore adoption1d25afd

lines 142–143why, one step back
142called ``--help``, but this can be changed. If a command itself implements
143a parameter with the same name, the default help parameter stops accepting

Added an example for help parameter customization.Armin Ronacherbefore adoption6e98e9b

lines 144–147why, one step back
144it. There is a context setting that can be used to override the names of
145the help parameters called :attr:`~Context.help_option_names`.146147This example changes the default parameters to ``-h`` and ``--help``

Merge pull request #125 from iKevinY/doc-fixesArmin Ronacherbefore adoption1d25afd

line 148why, one step back
148instead of just ``--help``:

Added an example for help parameter customization.Armin Ronacherbefore adoption6e98e9b

lines 149–151why, one step back
149
150.. click:example::151

defaults -> settingsArmin Ronacherbefore adoption1bc0a19

line 152why, one step back
152 CONTEXT_SETTINGS = dict(help_option_names=['-h', '--help'])

Added an example for help parameter customization.Armin Ronacherbefore adoption6e98e9b

line 153why, one step back
153

defaults -> settingsArmin Ronacherbefore adoption1bc0a19

line 154why, one step back
154 @click.command(context_settings=CONTEXT_SETTINGS)

Added an example for help parameter customization.Armin Ronacherbefore adoption6e98e9b

lines 155–162why, one step back
155 def cli():
156 pass157158And what it looks like:159160.. click:run::161162 invoke(cli, ['-h'])