Skip to content
Myr

Merge pull request #21 from julen/doc-fixes

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Doc fixes

authored by Armin Ronacher · committed by Armin Ronacher · parents 7caa40d, d30014b · Browse files · 5 files+15 added−15 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

5 files+15 added−15 removed

  • other:+15 added−15 removed

5 files+15 added−15 removed

modified:docs/arguments.rst+2 added-2 removed
33 unmodified lines
34unlimited) number of arguments is accepted. This can be controlled with35the ``nargs`` parameter. If it's set to ``-1`` then an unlimited number36of arguments is accepted.3738The value is then passed as tuple. Note that only one argument really can39be set to ``nargs=-1`` and right now only the last.38The value is then passed as a tuple. Note that only one argument really39can be set to ``nargs=-1`` and right now only the last.4041Example::4243 @click.command()
71 unmodified lines
modified:docs/commands.rst+1 added-1 removed
87 unmodified lines
88 if __name__ == '__main__':89 cli(obj={})9091If the object is provided each context will pass the object onwards to92it's children, but at any level a context's object can be overridden. To92its children, but at any level a context's object can be overridden. To93reach to a parent ``context.parent`` can be used.9495In addition to that instead of passing an object down nothing stops the96application from modifying global state. For instance you could just flip
112 unmodified lines
modified:docs/complex.rst+5 added-5 removed
4 unmodified lines
56.. currentmodule:: click78Click is designed to write complex and simple CLI tools alike. However9the power of it's design is the ability to arbitrarily nest systems9the power of its design is the ability to arbitrarily nest systems10together. For instance in case you have ever used Django you will have11realized that it provides a command line utility. But so does Celery for12instance. So when using Celery with Django there are two tools that need13to interact with each other and be cross configured.
19 unmodified lines
33an application defined object optionally.3435Context objects build a linked list until they hit top one. Each context36is linked to the parent context. This allows a command to work below37another command and store it's own information there without having to be37another command and store its own information there without having to be38afraid of messing up the state of the parent command.3940Because the parent data is however available it's possible to navigate to41it if needed.4243Most of the time you don't see the context object, but when writing more44complex applications it comes in handy. This brings is to the next point44complex applications it comes in handy. This brings us to the next point.4546Calling Convention47``````````````````48
18 unmodified lines
6768The Root Command69````````````````7071At the toplevel we need a group that can hold all our commands. In this71At the top level we need a group that can hold all our commands. In this72case we use the basic :func:`click.group` which allows us to register73other click commands below it.7475For this command we also want to accept some parameters that configure the
63 unmodified lines
139140While not relevant for this particular program we want to build there is141also quite good support for interleaving systems. Imagine for instance142there would be this super cool plugin for our version control system that143needs a lot of configuration and wants to store it's own configuration as143needs a lot of configuration and wants to store its own configuration as144:attr:`~Context.obj`. If we would then attach another command below that,145all the sudden we would get the plugin config instead of our repo object.146147One obvious way is to store a reference to the repo on the plugin but then
23 unmodified lines
modified:docs/options.rst+6 added-6 removed
28 unmodified lines
2930In this case the option is of type :data:`INT` because the default value31is an integer.3233The name of the parameter is the longest33The name of the parameter is the longest.3435Multi Value Options36-------------------3738Sometimes you have options that take more than one argument. For options39only a fixed number of arguments is supported. This can be configured by40the ``nargs`` parameter. The values are then stored as tuple:40the ``nargs`` parameter. The values are then stored as a tuple.4142Example::4344
76 unmodified lines
121122Feature Switches123----------------124125In addition to boolean flag there are also feature switches. These are125In addition to boolean flags there are also feature switches. These are126implemented by setting multiple options to the same parameter name and by127defining a flag value. To set a default flag assign a value of `True` to128the flag that should be the default.129
23 unmodified lines
153---------154155Sometimes you want parameters that can either be provided from the command156line or if not, you want to ask for user input. This can be implemented157with click by defining a prompt string:157with click by defining a prompt string.158159Example::160161 import os
58 unmodified lines
220---------------------------221222Sometimes you want a parameter to completely change the execution flow.223This for instance is the case when you want to have a ``--version``224parameter that prints out the version and then exists the application.224parameter that prints out the version and then exits the application.225226In such cases you need two concepts: eager parameters and a callback. An227eager parameter is a parameter that is handled before others and a228callback is what executes after the parameter is handled. The eagerness
80 unmodified lines
309This is supported by click in two ways. One is to automatically build310environment variables which is supported for options only. To enable this311feature the ``auto_envvar_prefix`` parameter needs to be passed to the312script that is invoked. Each command and parameter is then added as313underscore separated variable in uppercase. So if you have a subcommand313underscore-separated variable in uppercase. So if you have a subcommand314called ``foo`` taking an option called ``bar`` and the prefix is315``MY_TOOL`` then the variable is ``MY_TOOL_FOO_BAR``.316317Example usage::
36 unmodified lines
modified:docs/setuptools.rst+1 added-1 removed
52 unmodified lines
53 )5455The magic is in the ``entry_points`` parameter. Below ``console_scripts``56each line identifies one console script. The first part before the equals57sign (``=``) is the name of the script that should be generate, the second57sign (``=``) is the name of the script that should be generated, the second58part is the import path followed by a colon (``:``) with the click59command.6061That's it.
15 unmodified lines