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
Provenance
- Commit
a4b7d70- Tree
dcad6f7- Author
Armin Ronacher <armin.ronacher@active-4.com>- Committer
Armin Ronacher <armin.ronacher@active-4.com>- Parent 1
7caa40d- Parent 2
d30014b
5 files changed+15 added−15 removed
modified:docs/arguments.rst+2 added-2 removed
33 unmodified lines34 unlimited) number of arguments is accepted. This can be controlled with35 the ``nargs`` parameter. If it's set to ``-1`` then an unlimited number36 of arguments is accepted.37 38-The value is then passed as tuple. Note that only one argument really can39-be set to ``nargs=-1`` and right now only the last.38+The value is then passed as a tuple. Note that only one argument really39+can be set to ``nargs=-1`` and right now only the last.40 41 Example::42 43 @click.command()71 unmodified linesmodified:docs/commands.rst+1 added-1 removed
87 unmodified lines88 if __name__ == '__main__':89 cli(obj={})90 91 If the object is provided each context will pass the object onwards to92-it's children, but at any level a context's object can be overridden. To92+its children, but at any level a context's object can be overridden. To93 reach to a parent ``context.parent`` can be used.94 95 In addition to that instead of passing an object down nothing stops the96 application from modifying global state. For instance you could just flip112 unmodified linesmodified:docs/complex.rst+5 added-5 removed
4 unmodified lines5 6 .. currentmodule:: click7 8 Click is designed to write complex and simple CLI tools alike. However9-the power of it's design is the ability to arbitrarily nest systems9+the power of its design is the ability to arbitrarily nest systems10 together. For instance in case you have ever used Django you will have11 realized that it provides a command line utility. But so does Celery for12 instance. So when using Celery with Django there are two tools that need13 to interact with each other and be cross configured.19 unmodified lines33 an application defined object optionally.34 35 Context objects build a linked list until they hit top one. Each context36 is linked to the parent context. This allows a command to work below37-another command and store it's own information there without having to be37+another command and store its own information there without having to be38 afraid of messing up the state of the parent command.39 40 Because the parent data is however available it's possible to navigate to41 it if needed.42 43 Most of the time you don't see the context object, but when writing more44-complex applications it comes in handy. This brings is to the next point44+complex applications it comes in handy. This brings us to the next point.45 46 Calling Convention47 ``````````````````48 18 unmodified lines67 68 The Root Command69 ````````````````70 71-At the toplevel we need a group that can hold all our commands. In this71+At the top level we need a group that can hold all our commands. In this72 case we use the basic :func:`click.group` which allows us to register73 other click commands below it.74 75 For this command we also want to accept some parameters that configure the63 unmodified lines139 140 While not relevant for this particular program we want to build there is141 also quite good support for interleaving systems. Imagine for instance142 there would be this super cool plugin for our version control system that143-needs a lot of configuration and wants to store it's own configuration as143+needs a lot of configuration and wants to store its own configuration as144 :attr:`~Context.obj`. If we would then attach another command below that,145 all the sudden we would get the plugin config instead of our repo object.146 147 One obvious way is to store a reference to the repo on the plugin but then23 unmodified linesmodified:docs/options.rst+6 added-6 removed
28 unmodified lines29 30 In this case the option is of type :data:`INT` because the default value31 is an integer.32 33-The name of the parameter is the longest33+The name of the parameter is the longest.34 35 Multi Value Options36 -------------------37 38 Sometimes you have options that take more than one argument. For options39 only a fixed number of arguments is supported. This can be configured by40-the ``nargs`` parameter. The values are then stored as tuple:40+the ``nargs`` parameter. The values are then stored as a tuple.41 42 Example::43 44 76 unmodified lines121 122 Feature Switches123 ----------------124 125-In addition to boolean flag there are also feature switches. These are125+In addition to boolean flags there are also feature switches. These are126 implemented by setting multiple options to the same parameter name and by127 defining a flag value. To set a default flag assign a value of `True` to128 the flag that should be the default.129 23 unmodified lines153 ---------154 155 Sometimes you want parameters that can either be provided from the command156 line or if not, you want to ask for user input. This can be implemented157-with click by defining a prompt string:157+with click by defining a prompt string.158 159 Example::160 161 import os58 unmodified lines220 ---------------------------221 222 Sometimes you want a parameter to completely change the execution flow.223 This for instance is the case when you want to have a ``--version``224-parameter that prints out the version and then exists the application.224+parameter that prints out the version and then exits the application.225 226 In such cases you need two concepts: eager parameters and a callback. An227 eager parameter is a parameter that is handled before others and a228 callback is what executes after the parameter is handled. The eagerness80 unmodified lines309 This is supported by click in two ways. One is to automatically build310 environment variables which is supported for options only. To enable this311 feature the ``auto_envvar_prefix`` parameter needs to be passed to the312 script that is invoked. Each command and parameter is then added as313-underscore separated variable in uppercase. So if you have a subcommand313+underscore-separated variable in uppercase. So if you have a subcommand314 called ``foo`` taking an option called ``bar`` and the prefix is315 ``MY_TOOL`` then the variable is ``MY_TOOL_FOO_BAR``.316 317 Example usage::36 unmodified linesmodified:docs/setuptools.rst+1 added-1 removed
52 unmodified lines53 )54 55 The magic is in the ``entry_points`` parameter. Below ``console_scripts``56 each line identifies one console script. The first part before the equals57-sign (``=``) is the name of the script that should be generate, the second57+sign (``=``) is the name of the script that should be generated, the second58 part is the import path followed by a colon (``:``) with the click59 command.60 61 That's it.15 unmodified lines