You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* ``nargs``: Sets the number of arguments. Set to -1 to take an arbitrary number.
16
+
*`default`: Passes a default.
17
+
*`nargs`: Sets the number of arguments. Set to -1 to take an arbitrary number.
18
18
19
-
Basic Arguments
20
-
---------------
19
+
## Basic Arguments
21
20
22
-
A minimal :class:`click.Argument` solely takes one string argument: the name of the argument. This will assume the argument is required, has no default, and is of the type ``str``.
21
+
A minimal {class}`click.Argument` solely takes one string argument: the name of the argument. This will assume the argument is required, has no default, and is of the type `str`.
23
22
24
23
Example:
25
24
25
+
```{eval-rst}
26
26
.. click:example::
27
27
28
28
@click.command()
@@ -36,19 +36,21 @@ And from the command line:
36
36
.. click:run::
37
37
38
38
invoke(touch, args=['foo.txt'])
39
+
```
39
40
41
+
An argument may be assigned a {ref}`parameter type <parameter-types>`. If no type is provided, the type of the default value is used. If no default value is provided, the type is assumed to be {data}`STRING`.
40
42
41
-
An argument may be assigned a :ref:`parameter type <parameter-types>`. If no type is provided, the type of the default value is used. If no default value is provided, the type is assumed to be :data:`STRING`.
43
+
```{admonition} Note on Required Arguments
44
+
:class: note
42
45
43
-
.. admonition:: Note on Required Arguments
46
+
It is possible to make an argument required by setting `required=True`. It is not recommended since we think command line tools should gracefully degrade into becoming no ops. We think this because command line tools are often invoked with wildcard inputs and they should not error out if the wildcard is empty.
47
+
```
44
48
45
-
It is possible to make an argument required by setting ``required=True``. It is not recommended since we think command line tools should gracefully degrade into becoming no ops. We think this because command line tools are often invoked with wildcard inputs and they should not error out if the wildcard is empty.
49
+
## Multiple Arguments
46
50
47
-
Multiple Arguments
48
-
-----------------------------------
49
-
50
-
To set the number of argument use the ``nargs`` kwarg. It can be set to any positive integer and -1. Setting it to -1, makes the number of arguments arbitrary (which is called variadic) and can only be used once. The arguments are then packed as a tuple and passed to the function.
51
+
To set the number of argument use the `nargs` kwarg. It can be set to any positive integer and -1. Setting it to -1, makes the number of arguments arbitrary (which is called variadic) and can only be used once. The arguments are then packed as a tuple and passed to the function.
This is not how you should handle files and files paths. This merely used as a simple example. See :ref:`handling-files` to learn more about how to handle files in parameters.
74
+
This is not how you should handle files and files paths. This merely used as a simple example. See {ref}`handling-files` to learn more about how to handle files in parameters.
75
+
```
71
76
72
-
Argument Escape Sequences
73
-
---------------------------
77
+
## Argument Escape Sequences
74
78
75
-
If you want to process arguments that look like options, like a file named ``-foo.txt`` or ``--foo.txt`` , you must pass the ``--`` separator first. After you pass the ``--``, you may only pass arguments. This is a common feature for POSIX command line tools.
79
+
If you want to process arguments that look like options, like a file named `-foo.txt` or `--foo.txt` , you must pass the `--` separator first. After you pass the `--`, you may only pass arguments. This is a common feature for POSIX command line tools.
76
80
77
81
Example usage:
78
82
83
+
```{eval-rst}
79
84
.. click:example::
80
85
81
86
@click.command()
@@ -90,9 +95,11 @@ And from the command line:
90
95
.. click:run::
91
96
92
97
invoke(touch, ['--', '-foo.txt', 'bar.txt'])
98
+
```
93
99
94
-
If you don't like the ``--`` marker, you can set ignore_unknown_options to True to avoid checking unknown options:
100
+
If you don't like the `--` marker, you can set ignore_unknown_options to True to avoid checking unknown options:
0 commit comments