1- Click Concepts
2- ================
1+ # Click Concepts
32
43This section covers concepts about Click's design.
54
6- .. contents::
7- :depth: 1
8- :local:
5+ ``` {contents}
6+ ---
7+ depth: 1
8+ local: true
9+ ---
10+ ```
911
10- .. _ callback -evaluation-order:
12+ (callback -evaluation-order)=
1113
12- Callback Evaluation Order
13- -------------------------
14+ ## Callback Evaluation Order
1415
1516Click works a bit differently than some other command line parsers in that
1617it attempts to reconcile the order of arguments as defined by the
@@ -27,41 +28,41 @@ value as it happens, whereas a callback in Click is invoked after the
2728value has been fully converted.
2829
2930Generally, the order of invocation is driven by the order in which the user
30- 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 `` --bar
32- --foo `` , then the callback for `` bar`` will fire before the one for `` foo` `.
31+ provides the arguments to the script; if there is an option called ` --foo `
32+ and an option called ` --bar ` and the user calls it as ` --bar --foo ` , then
33+ the callback for ` bar ` will fire before the one for ` foo ` .
3334
3435There are three exceptions to this rule which are important to know:
3536
3637Eagerness:
37- An option can be set to be "eager". All eager parameters are
38- evaluated before all non-eager parameters, but again in the order as
39- they were provided on the command line by the user.
38+ > An option can be set to be "eager". All eager parameters are
39+ > evaluated before all non-eager parameters, but again in the order as
40+ > they were provided on the command line by the user.
4041
41- This is important for parameters that execute and exit like `` --help` `
42- and `` --version` `. Both are eager parameters, but whatever parameter
43- comes first on the command line will win and exit the program.
42+ > This is important for parameters that execute and exit like ` --help `
43+ > and ` --version ` . Both are eager parameters, but whatever parameter
44+ > comes first on the command line will win and exit the program.
4445
4546Repeated parameters:
46- If an option or argument is split up on the command line into multiple
47- places because it is repeated -- for instance, ` `--exclude foo --include
48- baz --exclude bar` ` -- the callback will fire based on the position of
49- the first option. In this case, the callback will fire for
50- `` exclude `` and it will be passed both options (`` foo ` ` and
51- `` bar `` ), then the callback for `` include `` will fire with `` baz ` `
52- only.
47+ > If an option or argument is split up on the command line into multiple
48+ > places because it is repeated -- for instance, `--exclude foo --include
49+ > baz --exclude bar` -- the callback will fire based on the position of
50+ > the first option. In this case, the callback will fire for
51+ > ` exclude ` and it will be passed both options (` foo ` and
52+ > ` bar ` ), then the callback for ` include ` will fire with ` baz `
53+ > only.
5354
54- Note that even if a parameter does not allow multiple versions, Click
55- will still accept the position of the first, but it will ignore every
56- value except the last. The reason for this is to allow composability
57- through shell aliases that set defaults.
55+ > Note that even if a parameter does not allow multiple versions, Click
56+ > will still accept the position of the first, but it will ignore every
57+ > value except the last. The reason for this is to allow composability
58+ > through shell aliases that set defaults.
5859
5960Missing parameters:
60- If a parameter is not defined on the command line, the callback will
61- still fire. This is different from how it works in optparse where
62- undefined values do not fire the callback. Missing parameters fire
63- their callbacks at the very end which makes it possible for them to
64- default to values from a parameter that came before.
61+ > If a parameter is not defined on the command line, the callback will
62+ > still fire. This is different from how it works in optparse where
63+ > undefined values do not fire the callback. Missing parameters fire
64+ > their callbacks at the very end which makes it possible for them to
65+ > default to values from a parameter that came before.
6566
6667Most of the time you do not need to be concerned about any of this,
6768but it is important to know how it works for some advanced cases.
0 commit comments