Skip to content
Myr

documentation.rst

This file

Path

docs/documentation.rst

88 lines · 2.3 KiB

Last changed by

Implemented and exposed click.echoArmin Ronacherbefore adoption95c24b3

History of this file

Take it

1Documenting 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.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 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 if43optional.  This can be customized at all levels:4445.. click:example::4647    @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            click.echo('Hello %s!' % name)5556Example:5758.. click:run::5960    invoke(hello, args=['--help'])61                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 too68long.  This can also be overridden:6970.. click:example::7172    @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."""8384And what it looks like:8586.. click:run::8788    invoke(cli, prog_name='repo.py')