refactor from rest to myst
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Jaron Rosenau · committed by Jaron Rosenau · parent d61103e · Browse files · 1 file·+34 added−33 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
1 file+34 added−33 removed
- other:+34 added−33 removed
Provenance
- Commit
b9a652b- Tree
9ab1221- Author
Jaron Rosenau <jaron.rosenau@gmail.com>- Committer
Jaron Rosenau <jaron.rosenau@gmail.com>- Parent
d61103e
1 file changed+34 added−33 removed
modified:docs/click-concepts.md+34 added-33 removed
121234678567891011101213121314151617188 unmodified lines27282930303132313233343536373738393839404141424342434445464647484950515247484950515253545455565755565758596060616263646162636465666768Click Concepts================# Click Concepts
This section covers concepts about Click's design.
.. contents:: :depth: 1 :local:```{contents}---depth: 1local: true---```
.. _callback-evaluation-order:(callback-evaluation-order)=
Callback Evaluation Order-------------------------## Callback Evaluation Order
Click works a bit differently than some other command line parsers in thatit attempts to reconcile the order of arguments as defined by theprogrammer with the order of arguments as defined by the user before8 unmodified linesvalue as it happens, whereas a callback in Click is invoked after thevalue has been fully converted.
Generally, the order of invocation is driven by the order in which the userprovides the arguments to the script; if there is an option called ``--foo``and an option called ``--bar`` and the user calls it as ``--bar--foo``, then the callback for ``bar`` will fire before the one for ``foo``.provides the arguments to the script; if there is an option called `--foo`and an option called `--bar` and the user calls it as `--bar --foo`, then the callback for `bar` will fire before the one for `foo`.
There are three exceptions to this rule which are important to know:
Eagerness: An option can be set to be "eager". All eager parameters are evaluated before all non-eager parameters, but again in the order as they were provided on the command line by the user.> An option can be set to be "eager". All eager parameters are> evaluated before all non-eager parameters, but again in the order as> they were provided on the command line by the user.
This is important for parameters that execute and exit like ``--help`` and ``--version``. Both are eager parameters, but whatever parameter comes first on the command line will win and exit the program.> This is important for parameters that execute and exit like `--help`> and `--version`. Both are eager parameters, but whatever parameter> comes first on the command line will win and exit the program.
Repeated parameters: If an option or argument is split up on the command line into multiple places because it is repeated -- for instance, ``--exclude foo --include baz --exclude bar`` -- the callback will fire based on the position of the first option. In this case, the callback will fire for ``exclude`` and it will be passed both options (``foo`` and ``bar``), then the callback for ``include`` will fire with ``baz`` only.> If an option or argument is split up on the command line into multiple> places because it is repeated -- for instance, `--exclude foo --include> baz --exclude bar` -- the callback will fire based on the position of> the first option. In this case, the callback will fire for> `exclude` and it will be passed both options (`foo` and> `bar`), then the callback for `include` will fire with `baz`> only.
Note that even if a parameter does not allow multiple versions, Click will still accept the position of the first, but it will ignore every value except the last. The reason for this is to allow composability through shell aliases that set defaults.> Note that even if a parameter does not allow multiple versions, Click> will still accept the position of the first, but it will ignore every> value except the last. The reason for this is to allow composability> through shell aliases that set defaults.
Missing parameters: If a parameter is not defined on the command line, the callback will still fire. This is different from how it works in optparse where undefined values do not fire the callback. Missing parameters fire their callbacks at the very end which makes it possible for them to default to values from a parameter that came before.> If a parameter is not defined on the command line, the callback will> still fire. This is different from how it works in optparse where> undefined values do not fire the callback. Missing parameters fire> their callbacks at the very end which makes it possible for them to> default to values from a parameter that came before.
Most of the time you do not need to be concerned about any of this,but it is important to know how it works for some advanced cases.