rename extension from .rst to .md
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 bb7be1f · Browse files · 2 files·+67 added−67 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+67 added−67 removed
- other:+67 added−67 removed
Provenance
- Commit
d61103e- Tree
bc33309- Author
Jaron Rosenau <jaron.rosenau@gmail.com>- Committer
Jaron Rosenau <jaron.rosenau@gmail.com>- Parent
bb7be1f
2 files changed+67 added−67 removed
added:docs/click-concepts.md+67 added
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667Click Concepts================
This section covers concepts about Click's design.
.. contents:: :depth: 1 :local:
.. _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 beforeinvoking any callbacks.
This is an important concept to understand when porting complexpatterns to Click from optparse or other systems. A parametercallback invocation in optparse happens as part of the parsing step,whereas a callback invocation in Click happens after the parsing.
The main difference is that in optparse, callbacks are invoked with the rawvalue 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``.
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.
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.
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.
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.deleted:docs/click-concepts.rst-67 removed
1-Click Concepts2-================3-4-This section covers concepts about Click's design.5-6-.. contents::7- :depth: 18- :local:9-10-.. _callback-evaluation-order:11-12-Callback Evaluation Order13--------------------------14-15-Click works a bit differently than some other command line parsers in that16-it attempts to reconcile the order of arguments as defined by the17-programmer with the order of arguments as defined by the user before18-invoking any callbacks.19-20-This is an important concept to understand when porting complex21-patterns to Click from optparse or other systems. A parameter22-callback invocation in optparse happens as part of the parsing step,23-whereas a callback invocation in Click happens after the parsing.24-25-The main difference is that in optparse, callbacks are invoked with the raw26-value as it happens, whereas a callback in Click is invoked after the27-value has been fully converted.28-29-Generally, the order of invocation is driven by the order in which the user30-provides the arguments to the script; if there is an option called ``--foo``31-and an option called ``--bar`` and the user calls it as ``--bar32---foo``, then the callback for ``bar`` will fire before the one for ``foo``.33-34-There are three exceptions to this rule which are important to know:35-36-Eagerness:37- An option can be set to be "eager". All eager parameters are38- evaluated before all non-eager parameters, but again in the order as39- they were provided on the command line by the user.40-41- This is important for parameters that execute and exit like ``--help``42- and ``--version``. Both are eager parameters, but whatever parameter43- comes first on the command line will win and exit the program.44-45-Repeated parameters:46- If an option or argument is split up on the command line into multiple47- places because it is repeated -- for instance, ``--exclude foo --include48- baz --exclude bar`` -- the callback will fire based on the position of49- the first option. In this case, the callback will fire for50- ``exclude`` and it will be passed both options (``foo`` and51- ``bar``), then the callback for ``include`` will fire with ``baz``52- only.53-54- Note that even if a parameter does not allow multiple versions, Click55- will still accept the position of the first, but it will ignore every56- value except the last. The reason for this is to allow composability57- through shell aliases that set defaults.58-59-Missing parameters:60- If a parameter is not defined on the command line, the callback will61- still fire. This is different from how it works in optparse where62- undefined values do not fire the callback. Missing parameters fire63- their callbacks at the very end which makes it possible for them to64- default to values from a parameter that came before.65-66-Most of the time you do not need to be concerned about any of this,67-but it is important to know how it works for some advanced cases.