documentation.rst
This file
Path
docs/documentation.rst
88 lines · 2.3 KiB
Last changed by
More automated docsArmin Ronacherbefore adoption8254b79
History of this fileTake it
Initial commitArmin Ronacherbefore adoption4101de3
lines 1–131Documenting Scripts2===================34Click makes it very easy to document your command line tools. First of5all it automatically generates help pages for you. While these are6currently not customizable in layout, all the texts can be changed.78Help Texts9----------1011Commands and options accept help arguments. In case of commands the doc12string of the function is automatically used if provided.13More automated docsArmin Ronacherbefore adoption8254b79
line 14why, one step back14Simple example:15More automated docsArmin Ronacherbefore adoption8254b79
lines 16–17why, one step back16.. click:example::17Initial commitArmin Ronacherbefore adoption4101de3
lines 18–2518 @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 print('Hello %s!' % name)25More automated docsArmin Ronacherbefore adoption8254b79
line 26why, one step back26And what it looks like:27More automated docsArmin Ronacherbefore adoption8254b79
line 28why, one step back28.. click:run::29More automated docsArmin Ronacherbefore adoption8254b79
line 30why, one step back30 invoke(hello, args=['--help'])Initial commitArmin Ronacherbefore adoption4101de3
lines 31–423132Arguments cannot be documented this way. This is to follow general33convention of Unix tools to use arguments only for the most necessary34things and to document them in the introduction text by referring to them35by name.3637Meta Vars38---------3940Options and parameters accept a ``metavar`` argument that can change the41meta variable in the help page. The default version is the parameter name42in uppercase with underscores and sometimes annotated differently ifMore automated docsArmin Ronacherbefore adoption8254b79
line 43why, one step back43optional. This can be customized at all levels:44More automated docsArmin Ronacherbefore adoption8254b79
lines 45–46why, one step back45.. click:example::46Initial commitArmin Ronacherbefore adoption4101de3
lines 47–5547 @click.command(options_metavar='<options>')48 @click.option('--count', default=1, help='number of greetings',49 metavar='<int>')50 @click.argument('name', metavar='<name>')51 def hello(count, name):52 """This script prints hello <name> <int> times."""53 for x in range(count):54 print('Hello %s!' % name)55More automated docsArmin Ronacherbefore adoption8254b79
line 56why, one step back56Example:57More automated docsArmin Ronacherbefore adoption8254b79
line 58why, one step back58.. click:run::59More automated docsArmin Ronacherbefore adoption8254b79
line 60why, one step back60 invoke(hello, args=['--help'])Initial commitArmin Ronacherbefore adoption4101de3
lines 61–6761 6263Command Short Help64------------------6566For commands a short help is generated. By default it's the first part67(until the first dot) of the help message of the command unless it's tooMore automated docsArmin Ronacherbefore adoption8254b79
line 68why, one step back68long. This can also be overridden:69More automated docsArmin Ronacherbefore adoption8254b79
lines 70–71why, one step back70.. click:example::71Initial commitArmin Ronacherbefore adoption4101de3
lines 72–8372 @click.group()73 def cli():74 """A simple command line tool."""7576 @cli.command('init', short_help='init the repo')77 def init():78 """Initializes the repository."""7980 @cli.command('delete', short_help='delete the repo')81 def delete():82 """Deletes the repository."""83More automated docsArmin Ronacherbefore adoption8254b79
line 84why, one step back84And what it looks like:85More automated docsArmin Ronacherbefore adoption8254b79
line 86why, one step back86.. click:run::87More automated docsArmin Ronacherbefore adoption8254b79
line 88why, one step back88 invoke(cli, prog_name='repo.py')