Documentation fixes
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Kevin Yap · committed by Kevin Yap · parent 1b9e2c0 · Browse files · 6 files·+145 added−145 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
6 files+145 added−145 removed
- other:+145 added−145 removed
Provenance
- Commit
d541802- Tree
67f1f2e- Author
Kevin Yap <me@kevinyap.ca>- Committer
Kevin Yap <me@kevinyap.ca>- Parent
1b9e2c0
6 files changed+145 added−145 removed
modified:docs/advanced.rst+18 added-18 removed
11 unmodified lines12 13 Command Aliases14 ---------------15 16-Many tools support aliases for commands. For instance you can configure16+Many tools support aliases for commands. For instance, you can configure17 ``git`` to accept ``git ci`` as alias for ``git commit``. Other tools18 also support auto discovery for aliases by automatically shortening them.19 20 Click does not support this out of the box but it's very easy to customize21 the :class:`Group` or any other :class:`MultiCommand` to provide this22 functionality.23 24-As explained in :ref:`custom-multi-commands` a multi command can provide24+As explained in :ref:`custom-multi-commands`, a multi command can provide25 two methods: :meth:`~MultiCommand.list_commands` and26 :meth:`~MultiCommand.get_command`. In this particular case you only need27 to override the latter as you generally don't want to enumerate the28 aliases on the help page to avoid confusion.29 30 This following example implements a subclass of :class:`Group` that31-accepts a prefix for a command. So if there is a command called32-``push`` it would accept ``pus`` as alias if it's unique:31+accepts a prefix for a command. If there is a command called32+``push`` it would accept ``pus`` as an alias if it's unique:33 34 .. click:example::35 36 class AliasedGroup(click.Group):9 unmodified lines46 elif len(matches) == 1:47 return click.Group.get_command(self, ctx, matches[0])48 ctx.fail('Too many matches: %s' % ', '.join(sorted(matches)))49 50-And it can be used like this then:50+And it can then be used like this:51 52 .. click:example::53 54 @click.command(cls=AliasedGroup)10 unmodified lines65 66 Invoking Other Commands67 -----------------------68 69-Sometimes it might be interesting to invoke one command from another70-command. This is generally a pattern that is discouraged with click but69+Sometimes, it might be interesting to invoke one command from another70+command. This is a pattern that is generally discouraged with click but71 possible nonetheless. For this you can use the :func:`Context.invoke`72 or :func:`Context.forward` methods.73 74-They work similar but the difference is that :func:`Context.invoke` merely74+They work similarly, but the difference is that :func:`Context.invoke` merely75 invokes another command with the arguments you provide as a caller,76 whereas :func:`Context.forward` fills in the arguments from the current77-command. Both accept the command as first argument and everything else is78-passed onwards as you would expect.77+command. Both accept the command as the first argument and everything else78+is passed onwards as you would expect.79 80 Example:81 82 .. click:example::37 unmodified lines120 The main difference is that in optparse callbacks are invoked with the raw121 value as it happens, whereas a callback in click is invoked after the122 value has been fully converted.123 124-Generally the order of invocation is driven by the order in which the user125-provides the arguments to the script. So if there is an option called126-``--foo`` and an option called ``--bar`` and the user calls it as ``--bar127---foo`` then the callback for ``bar`` will fire before the one for ``foo``.124+Generally, the order of invocation is driven by the order in which the user125+provides the arguments to the script; if there is an option called ``--foo``126+and an option called ``--bar`` and the user calls it as ``--bar127+--foo``, then the callback for ``bar`` will fire before the one for ``foo``.128 129 There are two exceptions to this rule which are important to know:130 131 Eagerness:1 unmodified line133 evaluated before all non-eager parameters, but again in the order as134 they were provided on the command line by the user.135 136 This is important for parameters that execute and exit like ``--help``137- and ``--version``. Both are eager parameters but whatever parameter137+ and ``--version``. Both are eager parameters, but whatever parameter138 comes first on the command line will win and exit the program.139 140 Repeated parameters:141 If an option or argument is split up on the command line into multiple142 places because it's repeated (for instance ``--exclude foo --include143- baz --exclude bar``) the callback will fire based on the position of144- the first option. So in this case the callback will fire for143+ baz --exclude bar``), the callback will fire based on the position of144+ the first option. In this case, the callback will fire for145 ``exclude`` and it will be passed both options (``foo`` and146 ``bar``), then the callback for ``include`` will fire with ``baz``147 only.148 2 unmodified lines151 value except the first. The reason for this is to allow composability152 through shell aliases that set defaults.153 154 Missing parameters:155- If a parameter is not defined on the command line the callback will155+ If a parameter is not defined on the command line, the callback will156 still fire. This is different from how it works in optparse where157 undefined values do not fire the callback. Missing parameters fire158 their callbacks at the very end which makes it possible for them to159 default to values from a parameter that came before.3 unmodified linesmodified:docs/arguments.rst+24 added-24 removed
67 unmodified lines68 69 If you come from ``argparse`` you might be missing support for setting70 ``nargs`` to ``+`` to indicate that at least one argument is required.71 72- This is supported by setting ``required=True``. However this should72+ This is supported by setting ``required=True``. However, this should73 not be used if you can avoid it as we believe scripts should gracefully74 degrade into becoming noops if a variadic argument is empty. The75- reason for this is that very often scripts are invoked with wildcard75+ reason for this is that very often, scripts are invoked with wildcard76 inputs from the command line and they should not error out if the77 wildcard is empty.78 79 .. _file-args:80 81 File Arguments82 --------------83 84-Since all the examples have already worked with file names it makes sense84+Since all the examples have already worked with filenames, it makes sense85 to explain how to deal with files properly. Command line tools are more86-fun if they work with files the unix way which is to accept ``-`` as a86+fun if they work with files the Unix way which is to accept ``-`` as a87 special file that refers to stdin/stdout.88 89 Click supports this through the :class:`click.File` type which90-intelligently handles files for you. It also deals with unicode and bytes90+intelligently handles files for you. It also deals with Unicode and bytes91 correctly for all versions of Python so your script stays very portable.92 93 Example:94 27 unmodified lines122 will be a unicode value always. Filenames unfortunately however can be123 unicode or bytes depending on which operating system you're on. As such124 the type is insufficient.125 126-Instead you should be using the :class:`Path` type which handles this127-complexity for you. Not only will it return either bytes or unicode126+Instead, you should be using the :class:`Path` type which handles this127+complexity for you. Not only will it return either bytes or Unicode128 depending on what makes more sense, but it will also be able to do some129 basic checks for you such as existence checks.130 131 Example:23 unmodified lines155 The :class:`FileType` type has one problem it needs to deal with and that156 is to decide when to open a file. The default behavior is to be157 "intelligent" about it. What this means is that it will open stdin/stdout158 and files opened for reading immediately. This will directly give the159-user feedback when a file cannot be opened. But it will only open files159+user feedback when a file cannot be opened, but it will only open files160 for writing the first time an IO operation is performed by wrapping the161 file automatically in a special wrapper.162 163 This behavior can be forced by passing ``lazy=True`` or ``lazy=False`` to164-the constructor. If the file is openened lazily it will fail on first IO164+the constructor. If the file is opened lazily, it will fail on first IO165 operation by raising an :exc:`FileError`.166 167-Since files opened for writing will typically immediatley empty the file,168-the lazy mode should really only be disabled if the developer is 100% sure167+Since files opened for writing will typically immediately empty the file,168+the lazy mode should only be disabled if the developer is absolutely sure169 that this is intended behavior.170 171-Forcing on lazy mode is also very useful to avoid resource handling172-confusion. If a file is opened in lazy mode it will get a173-``close_intelligently`` method that can help you figuring out if the file174-needs closing or not. This is not needed for parameters, but it is171+Forcing lazy mode is also very useful to avoid resource handling172+confusion. If a file is opened in lazy mode, it will receive a173+``close_intelligently`` method that can help figure out if the file174+needs closing or not. This is not needed for parameters, but is175 necessary for manually prompting with the :func:`prompt` function as you176-do not know if a stream like stdout was openend (which was already open176+do not know if a stream like stdout was opened (which was already open177 before) or a real file that needs closing.178 179 Starting with click 2.0 it's also possible to open files in atomic mode by180-passing ``atomic=True``. In atomic mode all writes go into a separate180+passing ``atomic=True``. In atomic mode, all writes go into a separate181 file in the same folder and upon completion the file will be moved over to182 the original location. This is useful if a file regularly read by other183 users is modified.184 185 Environment Variables186 ---------------------187 188 Like options, arguments can also get values from an environment variable.189-Unlike options however this is only supported for explicitly named189+Unlike options, however, this is only supported for explicitly named190 environment variables.191 192 Example usage:193 12 unmodified lines206 with open('hello.txt', 'w') as f:207 f.write('Hello World!')208 invoke(echo, env={'SRC': 'hello.txt'})209 210-In that case it can also be a list of different environment variables210+In that case, it can also be a list of different environment variables211 where the first one is picked.212 213 Generally this feature is not recommended because it can cause a lot of214 confusion to the user.215 216-Arguments looking like Options216+Arguments-Like Options217 ------------------------------218 219 Sometimes you want to process arguments that look like options. For220-instance imagine you have a file named ``-foo.txt``. If you pass this as221-such as an argument click will treat it as an option.220+instance, imagine you have a file named ``-foo.txt``. If you pass this as221+an argument in this manner, click will treat it as an option.222 223-To solve this, click does what any POSIX style command line script does223+To solve this, click does what any POSIX style command line script does,224 and that is to accept the string ``--`` as a separator for options and225-arguments. After the ``--`` marker all further parameters are accepted as225+arguments. After the ``--`` marker, all further parameters are accepted as226 arguments.227 228 Example usage:229 13 unmodified linesmodified:docs/bashcomplete.rst+13 added-13 removed
1 unmodified line2 =============3 4 .. versionadded:: 2.05 6-Starting with click 2.0 there is built-in support for bash completion for6+As of click 2.0, there is built-in support for Bash completion for7 any click script. There are certain restrictions on when this completion8-is available but for the most part it should just work.8+is available, but for the most part it should just work.9 10 Limitations11 -----------12 13 Bash completion is only available if a script has been installed properly14 and not executed through the ``python`` command. For information about15-how to do that see :ref:`setuptools-integration`. Currently click also15+how to do that see :ref:`setuptools-integration`. Also, click currently16 only supports completion for bash.17 18-Currently bash completion is an internal feature that is not customizable.18+Currently, bash completion is an internal feature that is not customizable.19 This might be relaxed in future versions.20 21 What it Completes22 -----------------23 24-Generally the bash completion support will complete subcommands and24+Generally, the bash completion support will complete subcommands and25 parameters. Subcommands are always listed whereas parameters only if at26 least a dash has been provided. Example::27 28 $ repo <TAB><TAB>29- clone commit copy delete setuser 29+ clone commit copy delete setuser30 $ repo clone -<TAB><TAB>31- --deep --help --rev --shallow -r 31+ --deep --help --rev --shallow -r32 33 Activation34 ----------35 36-In order to activate bash completion you need to inform bash that36+In order to activate Bash completion you need to inform Bash that37 completion is available for your script and how. Any click application38 automatically provides support for that. The general way this works is39-through a magic environment variable called ``_<PROG_NAME>_COMPLETE``39+through a magic environment variable called ``_<PROG_NAME>_COMPLETE``,40 where ``<PROG_NAME>`` is your application executable name in uppercase41 with dashes replaced by underscores.42 43-So if your tool is called ``foo-bar`` then the magic variable is called43+If your tool is called ``foo-bar``, then the magic variable is called44 ``_FOO_BAR_COMPLETE``. By exporting it with the ``source`` value it will45 spit out the activation script which can be trivally activated.46 47-For instance to enable bash completion for your ``foo-bar`` script, this47+For instance, to enable Bash completion for your ``foo-bar`` script, this48 is what you would need to put into your ``.bashrc``::49 50 eval "$(_FOO_BAR_COMPLETE=source foo-bar)"51 52-From this point onwards your script will have bash completion enabled.52+From this point onwards your script will have Bash completion enabled.53 54 Activation Script55 -----------------56 57 The above activation example will always invoke your application on58 startup. This might be slowing down the shell activation time59 significantly if you have many applications. Alternatively you could also60-ship a file with the contents of that which is what git and other systems60+ship a file with the contents of that which is what Git and other systems61 are doing.62 63 This can be easily accomplished::64 5 unmodified linesmodified:docs/commands.rst+34 added-35 removed
8 unmodified lines9 10 Callback Invocation11 -------------------12 13-For a regular command the callback is executed whenever the command runs.14-So if the script is the only command it will always fire (unless a15-parameter callback prevents it. This for instance happens if someone13+For a regular command, the callback is executed whenever the command runs.14+If the script is the only command it will always fire (unless a15+parameter callback prevents it). This for instance happens if someone16 passes ``--help`` to the script).17 18-For groups and multi commands the situation looks different. In that case18+For groups and multi commands, the situation looks different. In this case,19 the callback fires whenever a subcommand fires (unless this behavior is20 changed). What this means in practice is that an outer command runs21 when an inner command runs:22 18 unmodified lines41 42 Nested Handling and Contexts43 ----------------------------44 45-As you can see from the earlier example the basic command group accepts a45+As you can see from the earlier example, the basic command group accepts a46 debug argument which is passed to its callback, but not to the sync47 command itself. The sync command only accepts its own arguments.48 49-This allows tools to act completely independent of each other. But how49+This allows tools to act completely independent of each other, but how50 does one command talk to a nested one? The answer to this is the51 :class:`Context`.52 53-Each time a command is invoked a new context is created and linked with the54-parent context. Normally you can't see these contexts, but they are53+Each time a command is invoked, a new context is created and linked with the54+parent context. Normally, you can't see these contexts, but they are55 there. Contexts are passed to parameter callbacks together with the56 value automatically. Commands can also ask for the context to be passed57 by marking themselves with the :func:`pass_context` decorator. In that58-case the context is passed as first argument.58+case, the context is passed as first argument.59 60 The context can also carry a program specified object that can be61 used for the program's purposes. What this means is that you can build a62 script like this:13 unmodified lines76 77 if __name__ == '__main__':78 cli(obj={})79 80-If the object is provided each context will pass the object onwards to80+If the object is provided, each context will pass the object onwards to81 its children, but at any level a context's object can be overridden. To82-reach to a parent ``context.parent`` can be used.82+reach to a parent, ``context.parent`` can be used.83 84-In addition to that instead of passing an object down nothing stops the85-application from modifying global state. For instance you could just flip84+In addition to that, instead of passing an object down, nothing stops the85+application from modifying global state. For instance, you could just flip86 a global ``DEBUG`` variable and be done with it.87 88 Decorating Commands89 -------------------90 91-As you have seen in the earlier example a decorator can change how a91+As you have seen in the earlier example, a decorator can change how a92 command is invoked. What actually happens behind the scenes is that93 callbacks are always invoked through the :meth:`Context.invoke` method94 which automatically invokes a command correctly (by either passing the95 context or not).96 97 This is very useful when you want to write custom decorators. For98-instance a common pattern would be to configure an object representing98+instance, a common pattern would be to configure an object representing99 state and then storing it on the context and then to use a custom100 decorator to find the most recent object of this sort and pass it as first101 argument.102 103-For instance the :func:`pass_obj` decorator can be implemented like this:103+For instance, the :func:`pass_obj` decorator can be implemented like this:104 105 .. click:example::106 107 from functools import update_wrapper4 unmodified lines112 return ctx.invoke(f, ctx.obj, *args, **kwargs)113 return update_wrapper(new_func, f)114 115 The :meth:`Context.invoke` command will automatically invoke the function116-in the correct way. So the function will either be called with ``f(ctx,116+in the correct way, so the function will either be called with ``f(ctx,117 obj)`` or ``f(obj)`` depending on if it itself is decorated with118 :func:`with_context`.119 120 This is a very powerful context that can be used to build very complex2 unmodified lines123 124 Group Invocation Without Command125 --------------------------------126 127-By default a group or multi command is not invoked unless a subcommand is127+By default, a group or multi command is not invoked unless a subcommand is128 passed. In fact, not providing a command automatically passes ``--help``129 by default. This behavior can be changed by passing130-``invoke_without_command=True`` to a group. In that case the callback is130+``invoke_without_command=True`` to a group. In that case, the callback is131 always invoked instead of showing the help page. The context object also132-includes information about if the invocation would go to a subcommand or133-not.132+includes information about whether or not the invocation would go to a133+subcommand.134 135 Example:136 137 .. click:example::11 unmodified lines149 click.echo('The subcommand')150 151 And how it works in practice::152 153- $ python tool.py 153+ $ python tool.py154 I was invoked without subcommand155 $ python tool.py sync156 I am about to invoke sync157 The subcommand2 unmodified lines160 161 Custom Multi Commands162 ---------------------163 164-In addition to using :func:`click.group` you can also build your own164+In addition to using :func:`click.group`, you can also build your own165 custom multi commands. This is useful when you want to support commands166 being loaded lazily from plugins.167 168 A custom multi command just needs to implement a list and load method:39 unmodified lines208 209 Merging Multi Commands210 ----------------------211 212-In addition to implementing custom multi commands it can also be212+In addition to implementing custom multi commands, it can also be213 interesting to merge multiple together into one script. While this is214-generally not as recommended as nesting one below the other the merging214+generally not as recommended as nesting one below the other, the merging215 approach can be useful in some circumstances for a nicer shell experience.216 217 A default implementation for such a merging system is the218 :class:`CommandCollection` class. It accepts a list of other multi219-commands and makes the commands available on the same class. It accepts a220-list of other multi commands and makes the commands available on the same221-level.219+commands and makes the commands available on the same level.220 221 Example usage:222 223 .. click:example::26 unmodified lines250 .. click:run::251 252 invoke(cli, prog_name='cli', args=['--help'])253 256-In case a command exists on more than one source, the first source wins.254+In case a command exists in more than one source, the first source wins.255 256 Overriding Defaults257 -------------------258 261-By default the default value for a parameter is pulled from the262-``default`` flag that is provided when it's defined. But that's not the259+By default, the default value for a parameter is pulled from the260+``default`` flag that is provided when it's defined, but that's not the261 only place defaults can be loaded from. The other place is the262 :attr:`Context.default_map` (a dictionary) on the context. This allows265-defaults to be loaded from a config file to override the regular defaults.263+defaults to be loaded from a configuration file to override the regular264+defaults.265 266 This is useful if you plug in some commands from another package but267 you're not satisfied with the defaults.268 269 The default map can be nested arbitrarily for each subcommand and be271-provided when the script is invoked. Alternatively it can also be272-overriden at any point by commands. For instance a toplevel command could273-load the defaults from a config file.270+provided when the script is invoked. Alternatively, it can also be271+overriden at any point by commands. For instance a top-level command could272+load the defaults from a configuration file.273 274 Example usage:275 276 .. click:example::26 unmodified linesmodified:docs/complex.rst+53 added-52 removed
3 unmodified lines4 ====================5 6 .. currentmodule:: click7 8-Click is designed to write complex and simple CLI tools alike. However9-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 need8+Click is designed to assist with the creation of complex and simple CLI tools9+alike. However, the power of its design is the ability to arbitrarily nest10+systems together. For instance, in case you have ever used Django, you will11+have realized that it provides a command line utility, but so does Celery (for12+instance). When using Celery with Django there are two tools that need13 to interact with each other and be cross configured.14 15 In a theoretical world of two separate click command line utilities they16-can solve this problem by nesting one inside the other. For instance the16+can solve this problem by nesting one inside the other. For instance, the17 web framework could also load the commands for the message queue18 framework.19 20 Basic Concepts4 unmodified lines25 26 Contexts27 ````````28 29-Whenever a click command is executed a :class:`Context` object is created30-which holds state for this particular invocation. For instance it31-remembers parsed parameters, what command created it, which resources need32-to be cleaned up at the end of the function and so forth. It also holds33-an application defined object optionally.29+Whenever a click command is executed, a :class:`Context` object is created30+which holds state for this particular invocation. It remembers parsed31+parameters, what command created it, which resources need to be cleaned up32+at the end of the function, and so forth. It can also optionally hold an33+application-defined object.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 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 to40+Because the parent data is available, however, it is 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 us to the next point.45 46 Calling Convention47 ``````````````````48 49-When a click command callback is executed it's passed all the non hidden50-parameters as keyword arguments. Notably absent is the context. However51-a callback can opt-into being passed the context object by marking itself49+When a click command callback is executed, it's passed all the non-hidden50+parameters as keyword arguments. Notably absent is the context. However,51+a callback can opt into being passed the context object by marking itself52 with :func:`pass_context`.53 54 So how do you invoke a command callback if you don't know if it should55 receive the context or not? The answer is that the context itself56 provides a helper function (:meth:`Context.invoke`) which can do this for57 you. It accepts the callback as first argument and then invokes the58 function correctly.59 60-Building a Git61---------------60+Building a Git Clone61+--------------------62 63 In this example we want to build a command line tool that resembles a64-version control system a bit. Systems like git usually provide one64+version control system. Systems like Git usually provide one65 over-arching command that already accepts some parameters and66-configuration, and then has extra subcommands that do other things.66+configuration, and then have extra subcommands that do other things.67 68 The Root Command69 ````````````````70 71-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 register71+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 the76 state of our tool:21 unmodified lines98 99 So let's understand what this does. We create a group command which can100 have subcommands. When it is invoked it will create an instance of a101 ``Repo`` class. This holds the state for our command line tool. In this102-case it just remembers some parameters but at this point it could also103-start loading config files and so on.102+case it just remembers some parameters, but at this point it could also103+start loading configuration files and so on.104 105 This state object is then remembered as :attr:`~Context.obj` on the106 context. This is a special attribute where commands are supposed to107 remember what they need to pass on to their children.108 109-In order for this to work we need to mark our function with110-:func:`pass_context` because otherwise the context object would be109+In order for this to work, we need to mark our function with110+:func:`pass_context`, because otherwise the context object would be111 entirely hidden from us.112 113 The First Child Command114 ```````````````````````115 116-So let's add our first child command to it. Let's go with the clone117-command:116+Let's add our first child command to it, the clone command:117 118 .. click:example::119 120 @cli.command()2 unmodified lines123 def clone(src, dest):124 pass125 126 So now we have a clone command, but how do we get access to the repo? As128-you can imagine one way is to use the :func:`pass_context` function which127+you can imagine, one way is to use the :func:`pass_context` function which128 again will make our callback also get the context passed on which we130-memorized the repo. Even better there is a second version of this131-decorator called :func:`pass_obj` which will just pass the stored object,132-in our case the repo:129+memorized the repo. However, there is a second version of this decorator130+called :func:`pass_obj` which will just pass the stored object, (in our case131+the repo):132 133 .. click:example::134 135 @cli.command()5 unmodified lines141 142 Interleaved Commands143 ````````````````````144 146-While not relevant for this particular program we want to build there is147-also quite good support for interleaving systems. Imagine for instance145+While not relevant for the particular program we want to build, there is146+also quite good support for interleaving systems. Imagine for instance that147 there would be this super cool plugin for our version control system that148 needs a lot of configuration and wants to store its own configuration as149 :attr:`~Context.obj`. If we would then attach another command below that,151-all the sudden we would get the plugin config instead of our repo object.150+we would all of a sudden get the plugin configuration instead of our repo151+object.152 153-One obvious way is to store a reference to the repo on the plugin but then154-a command needs to be aware that it's attached below such a plugin.153+One obvious way to remedy this is to store a reference to the repo in the154+plugin, but then a command needs to be aware that it's attached below such a155+plugin.156 156-There is a much better system by taking advantage of the linked nature of157-contexts. We know that the plugin context is linked to the context that158-created our repo. Because of that we can start a search for the last157+There is a much better system that can built by taking advantage of the linked158+nature of contexts. We know that the plugin context is linked to the context159+that created our repo. Because of that, we can start a search for the last160 level where the object stored on the context was a repo.161 162 Built-in support for this is provided by the :func:`make_pass_decorator`162-factory which will create decorators for us that find objects (it163-internally calls into :meth:`Context.find_object`). So in our case we164-know that we want to find the closest ``Repo`` object. So let's make a163+factory, which will create decorators for us that find objects (it164+internally calls into :meth:`Context.find_object`). In our case, we165+know that we want to find the closest ``Repo`` object, so let's make a166 decorator for this:167 168 .. click:example::169 170 pass_repo = click.make_pass_decorator(Repo)171 171-If we now use ``pass_repo`` instead of ``pass_obj`` we will always get a172+If we now use ``pass_repo`` instead of ``pass_obj``, we will always get a173 repo instead of something else:174 175 .. click:example::176 3 unmodified lines180 @pass_repo181 def clone(repo, src, dest):182 pass183 183-Ensuring Objects184-````````````````184+Ensuring Object Creation185+````````````````````````186 187 The above example only works if there was an outer command that created a188 ``Repo`` object and stored it on the context. For some more advanced use188-cases this might be a problem for you. The default behavior of189-:func:`make_pass_decorator` is to call into :meth:`Context.find_object`190-which will find the object. If it can't find the object it will raise an189+cases, this might become a problem. The default behavior of190+:func:`make_pass_decorator` is to call :meth:`Context.find_object`191+which will find the object. If it can't find the object, it will raise an192 error. The alternative behavior is to use :meth:`Context.ensure_object`192-which will find the object, or if it cannot find it, will create one and193+which will find the object, and if it cannot find it, will create one and194 store it on the innermost context. This behavior can also be enabled for195 :func:`make_pass_decorator` by passing ``ensure=True``:196 197 .. click:example::198 199 pass_repo = click.make_pass_decorator(Repo, ensure=True)200 200-In this case the innermost context gets such an object created if it's201+In this case, the innermost context gets an object created if it is202 missing. This might replace objects being placed there earlier. In this202-case the command stays executable, even if the outer command does not run.203-For this to work the object type needs to have a constructor that accepts203+case, the command stays executable, even if the outer command does not run.204+For this to work, the object type needs to have a constructor that accepts205 no arguments.206 207 As such it runs standalone:208 12 unmodified linesmodified:docs/license.rst+3 added-3 removed
1 License2 =======3 4-Click is licensed under a three clause BSD License. It basically means:5-do whatever you want with it as long as the copyright in Click sticks4+Click is licensed under a three-clause BSD License. It basically means:5+do whatever you want with it as long as the copyright in click sticks6 around, the conditions are not modified and the disclaimer is present.7-Furthermore you must not use the names of the authors to promote derivatives7+Furthermore, you must not use the names of the authors to promote derivatives8 of the software without written consent.9 10 License Text11 ------------2 unmodified lines