Changed wording with respect to context objects
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 0f894fa · Browse files · 2 files·+10 added−10 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
2 files+10 added−10 removed
- other:+10 added−10 removed
Provenance
- Commit
30b66d9- Tree
205fc21- Author
Kevin Yap <me@kevinyap.ca>- Committer
Kevin Yap <me@kevinyap.ca>- Parent
0f894fa
2 files changed+10 added−10 removed
modified:docs/complex.rst+9 added-9 removed
30 unmodified lines31 at the end of the function, and so forth. It can also optionally hold an32 application-defined object.33 34 Context objects build a linked list until they hit the top one. Each context35-is linked to the parent context. This allows a command to work below35+is linked to a parent context. This allows a command to work below36 another command and store its own information there without having to be37 afraid of altering up the state of the parent command.38 39 Because the parent data is available, however, it is possible to navigate to6 unmodified lines46 ``````````````````47 48 When a click command callback is executed, it's passed all the non-hidden49 parameters as keyword arguments. Notably absent is the context. However,50-a callback can opt into being passed the context object by marking itself50+a callback can opt into being passed to the context object by marking itself51 with :func:`pass_context`.52 53 So how do you invoke a command callback if you don't know if it should54 receive the context or not? The answer is that the context itself45 unmodified lines100 ``Repo`` class. This holds the state for our command line tool. In this101 case, it just remembers some parameters, but at this point it could also102 start loading configuration files and so on.103 104-This state object is then remembered as :attr:`~Context.obj` on the105-context. This is a special attribute where commands are supposed to106-remember what they need to pass on to their children.104+This state object is then remembered by the context as :attr:`~Context.obj`.105+This is a special attribute where commands are supposed to remember what106+they need to pass on to their children.107 108 In order for this to work, we need to mark our function with109-:func:`pass_context`, because otherwise the context object would be109+:func:`pass_context`, because otherwise, the context object would be110 entirely hidden from us.111 112 The First Child Command113 ```````````````````````41 unmodified lines155 156 There is a much better system that can built by taking advantage of the linked157 nature of contexts. We know that the plugin context is linked to the context158 that created our repo. Because of that, we can start a search for the last159-level where the object stored on the context was a repo.159+level where the object stored by the context was a repo.160 161 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`). In our case, we19 unmodified lines183 Ensuring Object Creation184 ````````````````````````185 186 The above example only works if there was an outer command that created a187-``Repo`` object and stored it on the context. For some more advanced use187+``Repo`` object and stored it in the context. For some more advanced use188 cases, this might become a problem. The default behavior of189 :func:`make_pass_decorator` is to call :meth:`Context.find_object`190 which will find the object. If it can't find the object, it will raise an191 error. The alternative behavior is to use :meth:`Context.ensure_object`192 which will find the object, and if it cannot find it, will create one and193-store it on the innermost context. This behavior can also be enabled for193+store it in the innermost context. This behavior can also be enabled for194 :func:`make_pass_decorator` by passing ``ensure=True``:195 196 .. click:example::197 22 unmodified linesmodified:docs/options.rst+1 added-1 removed
329 unmodified lines330 331 The `expose_value` parameter prevents the pretty pointless ``version``332 parameter from being passed to the callback. If that was not specified, a333 boolean would be passed to the `hello` script. The `resilient_parsing`334-flag is set on the context if click wants to parse the command line334+flag is applied to the context if click wants to parse the command line335 without and destructive behavior that would change the execution flow. In336 this case, because we would exit the program, we instead do nothing.337 338 What it looks like:270 unmodified lines