Skip to content
Myr

documentation.rst

This file

Path

docs/documentation.rst

128 lines · 3.3 KiB

Last changed by

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

History of this file

Take it

The walk stopped after 200 commits: lines older than 09d219d point at it.

Added travis configArmin Ronacherbefore adoption09d219d

lines 1–4why, one step back
1Documenting Scripts
2===================34Click makes it very easy to document your command line tools. First of

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

lines 5–6why, one step back
5all, it automatically generates help pages for you. While these are
6currently not customizable in layout, all of the text can be changed.

Added travis configArmin Ronacherbefore adoption09d219d

lines 7–10why, one step back
7
8Help Texts9----------10

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

line 11why, one step back
11Commands and options accept help arguments. In the case of commands, the doc

Added travis configArmin Ronacherbefore adoption09d219d

lines 12–32why, one step back
12string of the function is automatically used if provided.
1314Simple example:1516.. click:example::1718 @click.command()19 @click.option('--count', default=1, help='number of greetings')20 @click.argument('name')21 def hello(count, name):22 """This script prints hello NAME COUNT times."""23 for x in range(count):24 click.echo('Hello %s!' % name)2526And what it looks like:2728.. click:run::2930 invoke(hello, args=['--help'])3132Arguments cannot be documented this way. This is to follow general

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

line 33why, one step back
33convention of Unix tools using arguments for only the most necessary

Added travis configArmin Ronacherbefore adoption09d219d

lines 34–36why, one step back
34things and to document them in the introduction text by referring to them
35by name.36

Added support for explicit terminal widths and disabling of rewrappingArmin Ronacherbefore adoption24d400f

lines 37–40why, one step back
37Preventing Rewrapping
38---------------------3940The default behavior of click is to rewrap text to work correctly for the

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

line 41why, one step back
41width of the terminal. In some circumstances, this can become a problem.

Added support for explicit terminal widths and disabling of rewrappingArmin Ronacherbefore adoption24d400f

lines 42–43why, one step back
42The main issue is showing code examples where newlines are significant.
43

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

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

Merge pull request #70 from julen/doc-fixesArmin Ronacherbefore adoption24b35b9

line 46why, one step back
46help text and rewrapping will be disabled.

Added support for explicit terminal widths and disabling of rewrappingArmin Ronacherbefore adoption24d400f

lines 47–76why, one step back
47
48Example:4950.. click:example::5152 @click.command()53 def cli():54 """First paragraph.5556 This is a very long second paragraph and as you57 can see wrapped very early in the source text58 but will be rewrapped to the terminal width in59 the final output.6061 \b62 This is63 a paragraph64 without rewrapping.6566 And this is a paragraph67 that will be rewrapped again.68 """6970And what it looks like:7172.. click:run::7374 invoke(cli, args=['--help'])7576

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

lines 77–78why, one step back
77Meta Variables
78--------------

Added travis configArmin Ronacherbefore adoption09d219d

lines 79–81why, one step back
79
80Options and parameters accept a ``metavar`` argument that can change the81meta variable in the help page. The default version is the parameter name

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

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

Added travis configArmin Ronacherbefore adoption09d219d

lines 84–101why, one step back
84
85.. click:example::8687 @click.command(options_metavar='<options>')88 @click.option('--count', default=1, help='number of greetings',89 metavar='<int>')90 @click.argument('name', metavar='<name>')91 def hello(count, name):92 """This script prints hello <name> <int> times."""93 for x in range(count):94 click.echo('Hello %s!' % name)9596Example:9798.. click:run::99100 invoke(hello, args=['--help'])101

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

line 102why, one step back
102

Added travis configArmin Ronacherbefore adoption09d219d

lines 103–105why, one step back
103Command Short Help
104------------------105

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

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

Added travis configArmin Ronacherbefore adoption09d219d

lines 109–128why, one step back
109
110.. click:example::111112 @click.group()113 def cli():114 """A simple command line tool."""115116 @cli.command('init', short_help='init the repo')117 def init():118 """Initializes the repository."""119120 @cli.command('delete', short_help='delete the repo')121 def delete():122 """Deletes the repository."""123124And what it looks like:125126.. click:run::127128 invoke(cli, prog_name='repo.py')