Skip to content
Myr

Docs: fixes

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Julen Ruiz Aizpuru · committed by Julen Ruiz Aizpuru · parent 5381d65 · Browse files · 1 file+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

1 file+10 added−10 removed

  • other:+10 added−10 removed

1 file+10 added−10 removed

modified:docs/advanced.rst+10 added-10 removed
123 unmodified lines
124Callback Evaluation Order125-------------------------126127Click works a bit different than some other command line parsers in that128it attempts to reconsiliate the order of arguments as defined by the128it attempts to reconcile the order of arguments as defined by the129programmer with the order of arguments as defined by the user before130invoking any callbacks.131132This is an important concept to understand when implementing complex
1 unmodified line
134callback invocation in optparse happens as part of the parsing step135whereas a callback invocation in click happens after the parsing.136137The main difference is that in optparse callbacks are invoked with the raw138value as it happens whereas a callback in click is invoked after the value139as fully converted.138value as it happens, whereas a callback in click is invoked after the139value has been fully converted.140141Generally the order of invocation is driven by the order in which the user142provides the arguments to the script. So if there is an option called143``--foo`` and an option called ``--bar`` and the user calls it as ``--bar144--foo`` then the callback for ``bar`` will fire before the one of ``foo``.144--foo`` then the callback for ``bar`` will fire before the one for ``foo``.145146There are two exceptions to this rule which are important to know:147148Eagerness:
1 unmodified line
150 evaluated before all non-eager parameters, but again in the order as151 they were provided on the command line by the user.152153 This is important for parameters that execute and exit like ``--help``154 and ``--version``. Both are eager parameters but whatever paramter154 and ``--version``. Both are eager parameters but whatever parameter155 comes first on the command line will win and exit the program.156157Repeated parameters:158 If an option or argument is split up on the command line into multiple
3 unmodified lines
162 ``exclude`` and it will be passed both options (``foo`` and163 ``bar``), then the callback for ``include`` will fire with ``baz``164 only.165166 Note that even if an parameter does not allow multiple versions click166 Note that even if a parameter does not allow multiple versions, click167 will still accept the position of the first, but it will ignore every168 value with the exception of the first. The reason for this is to169 allow composability through shell aliases that set defaults.168 value except the first. The reason for this is to allow composability169 through shell aliases that set defaults.170171Missing parameters:172 If an parameter is not defined on the command line the callback will172 If a parameter is not defined on the command line the callback will173 still fire. This is different from how it works in optparse where174 not defined values do not fire the callback. Missing parameters fire174 undefined values do not fire the callback. Missing parameters fire175 their callbacks at the very end which makes it possible for them to176 default to values from a parameter that came before.177178Most of the time you don't need to be concerned about any of this stuff,
1 unmodified line