click 8.3.2__tar.gz → 8.4.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {click-8.3.2 → click-8.4.0}/CHANGES.rst +142 -3
- {click-8.3.2 → click-8.4.0}/PKG-INFO +1 -1
- {click-8.3.2 → click-8.4.0}/docs/api.md +4 -0
- click-8.3.2/docs/arguments.rst → click-8.4.0/docs/arguments.md +58 -30
- click-8.4.0/docs/click-concepts.md +68 -0
- click-8.3.2/docs/commands-and-groups.rst → click-8.4.0/docs/commands-and-groups.md +151 -67
- click-8.3.2/docs/commands.rst → click-8.4.0/docs/commands.md +179 -140
- {click-8.3.2 → click-8.4.0}/docs/conf.py +1 -0
- click-8.4.0/docs/contributing.md +44 -0
- {click-8.3.2 → click-8.4.0}/docs/index.rst +2 -2
- click-8.4.0/docs/options.md +794 -0
- {click-8.3.2 → click-8.4.0}/docs/parameter-types.md +21 -2
- {click-8.3.2 → click-8.4.0}/docs/shell-completion.md +1 -1
- click-8.4.0/docs/standalone-apps.md +148 -0
- {click-8.3.2 → click-8.4.0}/docs/support-multiple-versions.md +1 -1
- {click-8.3.2 → click-8.4.0}/docs/testing.md +73 -6
- {click-8.3.2 → click-8.4.0}/docs/utils.md +13 -0
- {click-8.3.2 → click-8.4.0}/pyproject.toml +15 -1
- {click-8.3.2 → click-8.4.0}/src/click/__init__.py +3 -0
- {click-8.3.2 → click-8.4.0}/src/click/_compat.py +4 -0
- {click-8.3.2 → click-8.4.0}/src/click/_termui_impl.py +146 -89
- click-8.4.0/src/click/_textwrap.py +188 -0
- {click-8.3.2 → click-8.4.0}/src/click/_utils.py +4 -4
- {click-8.3.2 → click-8.4.0}/src/click/_winconsole.py +3 -2
- {click-8.3.2 → click-8.4.0}/src/click/core.py +232 -134
- {click-8.3.2 → click-8.4.0}/src/click/decorators.py +2 -2
- {click-8.3.2 → click-8.4.0}/src/click/exceptions.py +51 -15
- {click-8.3.2 → click-8.4.0}/src/click/formatting.py +15 -1
- {click-8.3.2 → click-8.4.0}/src/click/parser.py +19 -18
- {click-8.3.2 → click-8.4.0}/src/click/shell_completion.py +20 -8
- {click-8.3.2 → click-8.4.0}/src/click/termui.py +84 -26
- {click-8.3.2 → click-8.4.0}/src/click/testing.py +168 -6
- {click-8.3.2 → click-8.4.0}/src/click/types.py +228 -138
- {click-8.3.2 → click-8.4.0}/src/click/utils.py +22 -8
- {click-8.3.2 → click-8.4.0}/tests/test_commands.py +32 -0
- click-8.4.0/tests/test_compat.py +55 -0
- {click-8.3.2 → click-8.4.0}/tests/test_defaults.py +59 -2
- {click-8.3.2 → click-8.4.0}/tests/test_formatting.py +248 -0
- {click-8.3.2 → click-8.4.0}/tests/test_imports.py +11 -1
- {click-8.3.2 → click-8.4.0}/tests/test_options.py +973 -35
- {click-8.3.2 → click-8.4.0}/tests/test_shell_completion.py +50 -3
- {click-8.3.2 → click-8.4.0}/tests/test_termui.py +766 -4
- {click-8.3.2 → click-8.4.0}/tests/test_testing.py +278 -0
- {click-8.3.2 → click-8.4.0}/tests/test_types.py +20 -1
- {click-8.3.2 → click-8.4.0}/tests/test_utils.py +48 -14
- click-8.4.0/uv.lock +1665 -0
- click-8.3.2/docs/click-concepts.rst +0 -67
- click-8.3.2/docs/options.md +0 -500
- click-8.3.2/src/click/_textwrap.py +0 -51
- click-8.3.2/tests/test_compat.py +0 -10
- click-8.3.2/uv.lock +0 -1380
- {click-8.3.2 → click-8.4.0}/LICENSE.txt +0 -0
- {click-8.3.2 → click-8.4.0}/README.md +0 -0
- {click-8.3.2 → click-8.4.0}/docs/_static/click-icon.svg +0 -0
- {click-8.3.2 → click-8.4.0}/docs/_static/click-logo.svg +0 -0
- {click-8.3.2 → click-8.4.0}/docs/_static/click-name.svg +0 -0
- {click-8.3.2 → click-8.4.0}/docs/advanced.md +0 -0
- {click-8.3.2 → click-8.4.0}/docs/changes.rst +0 -0
- {click-8.3.2 → click-8.4.0}/docs/command-line-reference.md +0 -0
- {click-8.3.2 → click-8.4.0}/docs/complex.md +0 -0
- {click-8.3.2 → click-8.4.0}/docs/contrib.md +0 -0
- {click-8.3.2 → click-8.4.0}/docs/design-opinions.md +0 -0
- {click-8.3.2 → click-8.4.0}/docs/documentation.md +0 -0
- {click-8.3.2 → click-8.4.0}/docs/entry-points.md +0 -0
- {click-8.3.2 → click-8.4.0}/docs/exceptions.md +0 -0
- {click-8.3.2 → click-8.4.0}/docs/extending-click.md +0 -0
- {click-8.3.2 → click-8.4.0}/docs/faqs.md +0 -0
- {click-8.3.2 → click-8.4.0}/docs/handling-files.md +0 -0
- {click-8.3.2 → click-8.4.0}/docs/license.md +0 -0
- {click-8.3.2 → click-8.4.0}/docs/option-decorators.md +0 -0
- {click-8.3.2 → click-8.4.0}/docs/parameters.md +0 -0
- {click-8.3.2 → click-8.4.0}/docs/prompts.md +0 -0
- {click-8.3.2 → click-8.4.0}/docs/quickstart.md +0 -0
- {click-8.3.2 → click-8.4.0}/docs/setuptools.md +0 -0
- {click-8.3.2 → click-8.4.0}/docs/unicode-support.md +0 -0
- {click-8.3.2 → click-8.4.0}/docs/upgrade-guides.md +0 -0
- {click-8.3.2 → click-8.4.0}/docs/virtualenv.md +0 -0
- {click-8.3.2 → click-8.4.0}/docs/why.md +0 -0
- {click-8.3.2 → click-8.4.0}/docs/wincmd.md +0 -0
- {click-8.3.2 → click-8.4.0}/src/click/globals.py +0 -0
- {click-8.3.2 → click-8.4.0}/src/click/py.typed +0 -0
- {click-8.3.2 → click-8.4.0}/tests/conftest.py +0 -0
- {click-8.3.2 → click-8.4.0}/tests/test_arguments.py +0 -0
- {click-8.3.2 → click-8.4.0}/tests/test_basic.py +0 -0
- {click-8.3.2 → click-8.4.0}/tests/test_chain.py +0 -0
- {click-8.3.2 → click-8.4.0}/tests/test_command_decorators.py +0 -0
- {click-8.3.2 → click-8.4.0}/tests/test_context.py +0 -0
- {click-8.3.2 → click-8.4.0}/tests/test_custom_classes.py +0 -0
- {click-8.3.2 → click-8.4.0}/tests/test_info_dict.py +0 -0
- {click-8.3.2 → click-8.4.0}/tests/test_normalization.py +0 -0
- {click-8.3.2 → click-8.4.0}/tests/test_parser.py +0 -0
- {click-8.3.2 → click-8.4.0}/tests/test_stream_lifecycle.py +0 -0
- {click-8.3.2 → click-8.4.0}/tests/typing/typing_aliased_group.py +0 -0
- {click-8.3.2 → click-8.4.0}/tests/typing/typing_confirmation_option.py +0 -0
- {click-8.3.2 → click-8.4.0}/tests/typing/typing_group_kw_options.py +0 -0
- {click-8.3.2 → click-8.4.0}/tests/typing/typing_help_option.py +0 -0
- {click-8.3.2 → click-8.4.0}/tests/typing/typing_options.py +0 -0
- {click-8.3.2 → click-8.4.0}/tests/typing/typing_password_option.py +0 -0
- {click-8.3.2 → click-8.4.0}/tests/typing/typing_progressbar.py +0 -0
- {click-8.3.2 → click-8.4.0}/tests/typing/typing_simple_example.py +0 -0
- {click-8.3.2 → click-8.4.0}/tests/typing/typing_version_option.py +0 -0
|
@@ -1,7 +1,146 @@
|
|
|
1
1
|
.. currentmodule:: click
|
|
2
2
|
|
|
3
|
+
Version 8.4.0
|
|
4
|
+
-------------
|
|
5
|
+
|
|
6
|
+
Released 2026-05-17
|
|
7
|
+
|
|
8
|
+
- :class:`ParamType` typing improvements. :pr:`3371`
|
|
9
|
+
|
|
10
|
+
- :class:`ParamType` is now a generic abstract base class,
|
|
11
|
+
parameterized by its converted value type.
|
|
12
|
+
- :meth:`~ParamType.convert` return types are narrowed on all
|
|
13
|
+
concrete types (``str`` for :class:`STRING`, ``int`` for
|
|
14
|
+
:class:`INT`, etc.).
|
|
15
|
+
- :meth:`~ParamType.to_info_dict` returns specific
|
|
16
|
+
:class:`~typing.TypedDict` subclasses instead of
|
|
17
|
+
``dict[str, Any]``.
|
|
18
|
+
- :class:`CompositeParamType` and the number-range base are now
|
|
19
|
+
generic with abstract methods.
|
|
20
|
+
- Refactor ``convert_type`` to extract type inference into a private
|
|
21
|
+
``_guess_type`` helper, and add :func:`typing.overload` signatures.
|
|
22
|
+
:pr:`3372`
|
|
23
|
+
- :class:`Parameter` typing improvements. :pr:`2805`
|
|
24
|
+
|
|
25
|
+
- :class:`Parameter` is now an abstract base class, making explicit
|
|
26
|
+
that it cannot be instantiated directly.
|
|
27
|
+
- :attr:`Parameter.name` is now ``str`` instead of ``str | None``.
|
|
28
|
+
When ``expose_value=False``, the name is set to ``""`` instead
|
|
29
|
+
of ``None``.
|
|
30
|
+
- The ``ctx`` parameter of :meth:`Parameter.get_error_hint` is now
|
|
31
|
+
typed as ``Context | None``, matching the runtime behavior.
|
|
32
|
+
- Split string values from ``default_map`` for parameters with ``nargs > 1``
|
|
33
|
+
or :class:`Tuple` type, matching environment variable behavior.
|
|
34
|
+
:issue:`2745` :pr:`3364`
|
|
35
|
+
- Auto-detect ``type=UNPROCESSED`` for ``flag_value`` of non-basic types
|
|
36
|
+
(not ``str``, ``int``, ``float``, or ``bool``), so programmer-provided
|
|
37
|
+
Python objects like classes and enum members are passed through unchanged
|
|
38
|
+
instead of being stringified. Previously ``type=click.UNPROCESSED`` had
|
|
39
|
+
to be set explicitly. :issue:`2012` :pr:`3363`
|
|
40
|
+
- The error hint now uses :meth:`Command.get_help_option_names` to pick
|
|
41
|
+
non-shadowed help option names, so ``Try '... -h'`` no longer points to a
|
|
42
|
+
subcommand option that shadows ``-h``. All surviving names are shown
|
|
43
|
+
(``-h/--help``). :issue:`2790` :pr:`3208`
|
|
44
|
+
- Fix readline functionality on non-Windows platforms. Prompt text is now
|
|
45
|
+
passed directly to readline instead of being printed separately, allowing
|
|
46
|
+
proper backspace, line editing, and line wrapping behavior. :issue:`2968`
|
|
47
|
+
:pr:`2969`
|
|
48
|
+
- Use :func:`os.startfile` on Windows to open URLs in :func:`open_url`,
|
|
49
|
+
replacing the ``start`` built-in which cannot be invoked without
|
|
50
|
+
``shell=True``. :issue:`3164` :pr:`3186`
|
|
51
|
+
- Fix Fish shell completion errors when option help text contains newlines.
|
|
52
|
+
:issue:`3043` :pr:`3126`
|
|
53
|
+
- Add :class:`NoSuchCommand` exception with suggestions for misspelled
|
|
54
|
+
commands. :issue:`3107` :pr:`3228`
|
|
55
|
+
- Use :class:`ValueError` message when conversion in :class:`FuncParamType` would
|
|
56
|
+
fail. :issue:`3105` :pr:`3211`
|
|
57
|
+
- Add ``click.get_pager_file`` for file-like access to an output
|
|
58
|
+
pager. :pr:`1572` :pr:`3405`
|
|
59
|
+
- :class:`~click.formatting.TextWrapper` and
|
|
60
|
+
:func:`~click.formatting.wrap_text` now measure line width in visible
|
|
61
|
+
characters, ignoring ANSI escape sequences. :pr:`3420`
|
|
62
|
+
- Fix :meth:`HelpFormatter.write_usage` emitting only a blank line when
|
|
63
|
+
called without ``args``. The usage prefix and program name are now
|
|
64
|
+
written even when no arguments follow, and the trailing separator
|
|
65
|
+
space is stripped so the line ends at the program name.
|
|
66
|
+
:issue:`3360` :pr:`3434`
|
|
67
|
+
- Show custom error messages from types when :func:`prompt` with
|
|
68
|
+
``hide_input=True`` fails validation, instead of always showing a
|
|
69
|
+
generic message. Built-in type messages mask the input value.
|
|
70
|
+
:issue:`2809` :pr:`3256`
|
|
71
|
+
- Add ``capture`` parameter to :class:`CliRunner` with two modes: ``sys``
|
|
72
|
+
(default) and ``fd``. ``fd`` redirects file descriptors ``1`` and ``2``
|
|
73
|
+
via :func:`os.dup2` so output that bypasses ``sys.stdout`` (stale stream
|
|
74
|
+
references, C extensions, subprocesses, ``faulthandler``) is captured
|
|
75
|
+
with proper isolation. :issue:`854` :issue:`2412` :issue:`2468`
|
|
76
|
+
:issue:`2497` :issue:`2761` :issue:`2827` :issue:`2865`
|
|
77
|
+
- Revert the ``8.3.3`` change that exposed the original file descriptor
|
|
78
|
+
via ``fileno()`` on the redirected ``CliRunner`` streams in the default
|
|
79
|
+
capture mode. ``os.dup2(w, sys.stdout.fileno())`` calls inside a CLI no
|
|
80
|
+
longer mutate the host runner's stdout, which broke Pytest's ``fd``-level
|
|
81
|
+
capture teardown. C-level consumers that need a real ``fd`` should use
|
|
82
|
+
``capture="fd"``. :issue:`3384` :pr:`3391`
|
|
83
|
+
- Mark additional built-in strings with ``gettext()`` to extend translation
|
|
84
|
+
coverage. :pr:`2902`
|
|
85
|
+
- Fix feature switch groups (several ``flag_value`` options sharing one
|
|
86
|
+
parameter name) silently dropping an explicit ``default`` when a sibling
|
|
87
|
+
option without an explicit default was declared first. Arbitration is now
|
|
88
|
+
source-aware: a more explicit :class:`ParameterSource` always wins, and
|
|
89
|
+
within ``ParameterSource.DEFAULT``, an option that received an explicit
|
|
90
|
+
``default=`` keyword wins over a sibling whose default was auto-derived.
|
|
91
|
+
The 8.3.x first-wins fallback for remaining ties was reverted to the
|
|
92
|
+
pre-8.3.x last-wins fallback. :issue:`3403` :pr:`3404`
|
|
93
|
+
- Fix missing space between option help text and the ``(DEPRECATED)``
|
|
94
|
+
label, and localize the option label so it matches the command label.
|
|
95
|
+
The label and the ``DeprecationWarning`` reason suffix are now produced
|
|
96
|
+
by shared helpers. :pr:`3423`
|
|
97
|
+
- Document short option stacking (``-abc`` is parsed as ``-a -b -c``) and
|
|
98
|
+
clarify that multi-character short option names are not supported.
|
|
99
|
+
:issue:`2779` :pr:`3431`
|
|
100
|
+
|
|
101
|
+
Version 8.3.3
|
|
102
|
+
-------------
|
|
103
|
+
|
|
104
|
+
Released 2026-04-20
|
|
105
|
+
|
|
106
|
+
- Use :func:`shlex.split` to split pager and editor commands into ``argv``
|
|
107
|
+
lists for :class:`subprocess.Popen`, removing ``shell=True``.
|
|
108
|
+
:issue:`1026` :pr:`1477` :pr:`2775`
|
|
109
|
+
- Fix ``TypeError`` when rendering help for an option whose default value is
|
|
110
|
+
an object that doesn't support equality comparison with strings, such as
|
|
111
|
+
``semver.Version``. :issue:`3298` :pr:`3299`
|
|
112
|
+
- Fix pager test pollution under parallel execution by using pytest's
|
|
113
|
+
``tmp_path`` fixture instead of a shared temporary file path. :pr:`3238`
|
|
114
|
+
- Treat ``Sentinel.UNSET`` values in a ``default_map`` as absent, so they fall
|
|
115
|
+
through to the next default source instead of being used as the value.
|
|
116
|
+
:issue:`3224` :pr:`3240`
|
|
117
|
+
- Patch ``pdb.Pdb`` in ``CliRunner`` isolation so ``pdb.set_trace()``,
|
|
118
|
+
``breakpoint()``, and debuggers subclassing ``pdb.Pdb`` (ipdb, pdbpp) can
|
|
119
|
+
interact with the real terminal instead of the captured I/O streams.
|
|
120
|
+
:issue:`654` :issue:`824` :issue:`843` :pr:`951` :pr:`3235`
|
|
121
|
+
- Add optional randomized parallel test execution using ``pytest-randomly`` and
|
|
122
|
+
``pytest-xdist`` to detect test pollution and race conditions. :pr:`3151`
|
|
123
|
+
- Add contributor documentation for running stress tests, randomized
|
|
124
|
+
parallel tests, and Flask smoke tests. :pr:`3151` :pr:`3177`
|
|
125
|
+
- Show custom ``show_default`` string in prompts, matching the existing
|
|
126
|
+
help text behavior. :issue:`2836` :pr:`2837` :pr:`3165` :pr:`3262` :pr:`3280`
|
|
127
|
+
:pr:`3328`
|
|
128
|
+
- Fix ``default=True`` with boolean ``flag_value`` always returning the
|
|
129
|
+
``flag_value`` instead of ``True``. The ``default=True`` to ``flag_value``
|
|
130
|
+
substitution now only applies to non-boolean flags, where ``True`` acts as a
|
|
131
|
+
sentinel meaning "activate this flag by default". For boolean flags,
|
|
132
|
+
``default=True`` is returned as a literal value. :issue:`3111` :pr:`3239`
|
|
133
|
+
- Mark ``make_default_short_help`` as private API. :issue:`3189` :pr:`3250`
|
|
134
|
+
- ``CliRunner``'s redirected streams now expose the original file descriptor
|
|
135
|
+
via ``fileno()``, so that ``faulthandler``, ``subprocess``, and other
|
|
136
|
+
C-level consumers no longer crash with ``io.UnsupportedOperation``.
|
|
137
|
+
:issue:`2865`
|
|
138
|
+
- Change :class:`ParameterSource` to an :class:`~enum.IntEnum` and reorder
|
|
139
|
+
its members from most to least explicit, so values can be compared to
|
|
140
|
+
check whether a parameter was explicitly provided. :issue:`2879` :pr:`3248`
|
|
141
|
+
|
|
3
142
|
Version 8.3.2
|
|
4
|
-
|
|
143
|
+
-------------
|
|
5
144
|
|
|
6
145
|
Released 2026-04-02
|
|
7
146
|
|
|
@@ -19,7 +158,7 @@ Released 2026-04-02
|
|
|
19
158
|
``default=True``. :issue:`3121` :pr:`3201` :pr:`3213` :pr:`3225`
|
|
20
159
|
|
|
21
160
|
Version 8.3.1
|
|
22
|
-
|
|
161
|
+
-------------
|
|
23
162
|
|
|
24
163
|
Released 2025-11-15
|
|
25
164
|
|
|
@@ -901,7 +1040,7 @@ Released 2018-09-25
|
|
|
901
1040
|
so that changing the working directory does not affect it. :pr:`920`
|
|
902
1041
|
- Fix incorrect completions when defaults are present :issue:`925`,
|
|
903
1042
|
:pr:`930`
|
|
904
|
-
- Add copy option attrs so that custom classes can be
|
|
1043
|
+
- Add copy option attrs so that custom classes can be reused.
|
|
905
1044
|
:issue:`926`, :pr:`994`
|
|
906
1045
|
- "x" and "a" file modes now use stdout when file is ``"-"``.
|
|
907
1046
|
:pr:`929`
|
|
@@ -1,28 +1,31 @@
|
|
|
1
|
-
|
|
1
|
+
(arguments)=
|
|
2
2
|
|
|
3
|
-
Arguments
|
|
4
|
-
=========
|
|
3
|
+
# Arguments
|
|
5
4
|
|
|
6
|
-
|
|
5
|
+
```{currentmodule} click
|
|
6
|
+
```
|
|
7
7
|
|
|
8
8
|
Arguments are:
|
|
9
9
|
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
|
|
10
|
+
* Are positional in nature.
|
|
11
|
+
* Similar to a limited version of {ref}`options <options>` that
|
|
12
|
+
can take an arbitrary number of inputs
|
|
13
|
+
* {ref}`Documented manually <documenting-arguments>`.
|
|
13
14
|
|
|
14
15
|
Useful and often used kwargs are:
|
|
15
16
|
|
|
16
|
-
*
|
|
17
|
-
*
|
|
17
|
+
* `default`: Passes a default.
|
|
18
|
+
* `nargs`: Sets the number of arguments. Set to -1 to take an arbitrary number.
|
|
18
19
|
|
|
19
|
-
Basic Arguments
|
|
20
|
-
---------------
|
|
20
|
+
## Basic Arguments
|
|
21
21
|
|
|
22
|
-
A minimal
|
|
22
|
+
A minimal {class}`click.Argument` solely takes one string argument:
|
|
23
|
+
the name of the argument. This will assume the argument is required,
|
|
24
|
+
has no default, and is of the type `str`.
|
|
23
25
|
|
|
24
26
|
Example:
|
|
25
27
|
|
|
28
|
+
```{eval-rst}
|
|
26
29
|
.. click:example::
|
|
27
30
|
|
|
28
31
|
@click.command()
|
|
@@ -36,19 +39,31 @@ And from the command line:
|
|
|
36
39
|
.. click:run::
|
|
37
40
|
|
|
38
41
|
invoke(touch, args=['foo.txt'])
|
|
42
|
+
```
|
|
39
43
|
|
|
44
|
+
An argument may be assigned a {ref}`parameter type <parameter-types>`.
|
|
45
|
+
If no type is provided, the type of the default value is used. If no
|
|
46
|
+
default value is provided, the type is assumed to be {data}`STRING`.
|
|
40
47
|
|
|
41
|
-
|
|
48
|
+
```{admonition} Note on Required Arguments
|
|
49
|
+
:class: note
|
|
42
50
|
|
|
43
|
-
|
|
51
|
+
It is possible to make an argument required by setting
|
|
52
|
+
`required=True`. It is not recommended since we think command line
|
|
53
|
+
tools should gracefully degrade into becoming no ops. We think this
|
|
54
|
+
because command line tools are often invoked with wildcard inputs
|
|
55
|
+
and they should not error out if the wildcard is empty.
|
|
56
|
+
```
|
|
44
57
|
|
|
45
|
-
|
|
58
|
+
## Multiple Arguments
|
|
46
59
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
60
|
+
To set the number of argument use the `nargs` kwarg. It can be set to
|
|
61
|
+
any positive integer and -1. Setting it to -1, makes the number of
|
|
62
|
+
arguments arbitrary (which is called variadic) and can only be used
|
|
63
|
+
once. The arguments are then packed as a tuple and passed to the
|
|
64
|
+
function.
|
|
51
65
|
|
|
66
|
+
```{eval-rst}
|
|
52
67
|
.. click:example::
|
|
53
68
|
|
|
54
69
|
@click.command()
|
|
@@ -64,18 +79,26 @@ And from the command line:
|
|
|
64
79
|
.. click:run::
|
|
65
80
|
|
|
66
81
|
invoke(copy, args=['foo.txt', 'usr/david/foo.txt', 'usr/mitsuko/foo.txt'])
|
|
82
|
+
```
|
|
67
83
|
|
|
68
|
-
|
|
84
|
+
```{admonition} Note on Handling Files
|
|
85
|
+
:class: note
|
|
69
86
|
|
|
70
|
-
|
|
87
|
+
This is not how you should handle files and files paths. This
|
|
88
|
+
merely used as a simple example. See {ref}`handling-files` to learn
|
|
89
|
+
more about how to handle files in parameters.
|
|
90
|
+
```
|
|
71
91
|
|
|
72
|
-
Argument Escape Sequences
|
|
73
|
-
---------------------------
|
|
92
|
+
## Argument Escape Sequences
|
|
74
93
|
|
|
75
|
-
If you want to process arguments that look like options, like a file
|
|
94
|
+
If you want to process arguments that look like options, like a file
|
|
95
|
+
named `-foo.txt` or `--foo.txt`, you must pass the `--` separator
|
|
96
|
+
first. After you pass the `--`, you may only pass arguments. This is a
|
|
97
|
+
common feature for POSIX command line tools.
|
|
76
98
|
|
|
77
99
|
Example usage:
|
|
78
100
|
|
|
101
|
+
```{eval-rst}
|
|
79
102
|
.. click:example::
|
|
80
103
|
|
|
81
104
|
@click.command()
|
|
@@ -90,9 +113,12 @@ And from the command line:
|
|
|
90
113
|
.. click:run::
|
|
91
114
|
|
|
92
115
|
invoke(touch, ['--', '-foo.txt', 'bar.txt'])
|
|
116
|
+
```
|
|
93
117
|
|
|
94
|
-
If you don't like the
|
|
118
|
+
If you don't like the `--` marker, you can set
|
|
119
|
+
`ignore_unknown_options` to `True` to avoid checking unknown options:
|
|
95
120
|
|
|
121
|
+
```{eval-rst}
|
|
96
122
|
.. click:example::
|
|
97
123
|
|
|
98
124
|
@click.command(context_settings={"ignore_unknown_options": True})
|
|
@@ -107,17 +133,18 @@ And from the command line:
|
|
|
107
133
|
.. click:run::
|
|
108
134
|
|
|
109
135
|
invoke(touch, ['-foo.txt', 'bar.txt'])
|
|
136
|
+
```
|
|
110
137
|
|
|
138
|
+
(environment-variables)=
|
|
111
139
|
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
Environment Variables
|
|
115
|
-
---------------------
|
|
140
|
+
## Environment Variables
|
|
116
141
|
|
|
117
|
-
Arguments can use environment variables. To do so, pass the name(s) of
|
|
142
|
+
Arguments can use environment variables. To do so, pass the name(s) of
|
|
143
|
+
the environment variable(s) via `envvar` in `click.argument`.
|
|
118
144
|
|
|
119
145
|
Checking one environment variable:
|
|
120
146
|
|
|
147
|
+
```{eval-rst}
|
|
121
148
|
.. click:example::
|
|
122
149
|
|
|
123
150
|
@click.command()
|
|
@@ -156,3 +183,4 @@ And from the command line:
|
|
|
156
183
|
with open('hello.txt', 'w') as f:
|
|
157
184
|
f.write('Hello World from second variable!')
|
|
158
185
|
invoke(echo, env={'SRC_2': 'hello.txt'})
|
|
186
|
+
```
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
# Click Concepts
|
|
2
|
+
|
|
3
|
+
This section covers concepts about Click's design.
|
|
4
|
+
|
|
5
|
+
```{contents}
|
|
6
|
+
---
|
|
7
|
+
depth: 1
|
|
8
|
+
local: true
|
|
9
|
+
---
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
(callback-evaluation-order)=
|
|
13
|
+
|
|
14
|
+
## Callback Evaluation Order
|
|
15
|
+
|
|
16
|
+
Click works a bit differently than some other command line parsers in that
|
|
17
|
+
it attempts to reconcile the order of arguments as defined by the
|
|
18
|
+
programmer with the order of arguments as defined by the user before
|
|
19
|
+
invoking any callbacks.
|
|
20
|
+
|
|
21
|
+
This is an important concept to understand when porting complex
|
|
22
|
+
patterns to Click from optparse or other systems. A parameter
|
|
23
|
+
callback invocation in optparse happens as part of the parsing step,
|
|
24
|
+
whereas a callback invocation in Click happens after the parsing.
|
|
25
|
+
|
|
26
|
+
The main difference is that in optparse, callbacks are invoked with the raw
|
|
27
|
+
value as it happens, whereas a callback in Click is invoked after the
|
|
28
|
+
value has been fully converted.
|
|
29
|
+
|
|
30
|
+
Generally, the order of invocation is driven by the order in which the user
|
|
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`.
|
|
34
|
+
|
|
35
|
+
There are three exceptions to this rule which are important to know:
|
|
36
|
+
|
|
37
|
+
Eagerness:
|
|
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.
|
|
41
|
+
|
|
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.
|
|
45
|
+
|
|
46
|
+
Repeated parameters:
|
|
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.
|
|
54
|
+
|
|
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.
|
|
59
|
+
|
|
60
|
+
Missing parameters:
|
|
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.
|
|
66
|
+
|
|
67
|
+
Most of the time you do not need to be concerned about any of this,
|
|
68
|
+
but it is important to know how it works for some advanced cases.
|