Skip to content

Commit c8111c2

Browse files
authored
Move Arguments doc from reST to MyST (#3267)
2 parents a5cb82f + de3e8a3 commit c8111c2

1 file changed

Lines changed: 38 additions & 30 deletions

File tree

Lines changed: 38 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,28 @@
1-
.. _arguments:
1+
(arguments)=
22

3-
Arguments
4-
=========
3+
# Arguments
54

6-
.. currentmodule:: click
5+
```{currentmodule} click
6+
```
77

88
Arguments are:
99

10-
* Are positional in nature.
11-
* Similar to a limited version of :ref:`options <options>` that can take an arbitrary number of inputs
12-
* :ref:`Documented manually <documenting-arguments>`.
10+
* Are positional in nature.
11+
* Similar to a limited version of {ref}`options <options>` that can take an arbitrary number of inputs
12+
* {ref}`Documented manually <documenting-arguments>`.
1313

1414
Useful and often used kwargs are:
1515

16-
* ``default``: Passes a default.
17-
* ``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.
1818

19-
Basic Arguments
20-
---------------
19+
## Basic Arguments
2120

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`.
2322

2423
Example:
2524

25+
```{eval-rst}
2626
.. click:example::
2727
2828
@click.command()
@@ -36,19 +36,21 @@ And from the command line:
3636
.. click:run::
3737
3838
invoke(touch, args=['foo.txt'])
39+
```
3940

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`.
4042

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
4245
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+
```
4448

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
4650

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.
5152

53+
```{eval-rst}
5254
.. click:example::
5355
5456
@click.command()
@@ -64,18 +66,21 @@ And from the command line:
6466
.. click:run::
6567
6668
invoke(copy, args=['foo.txt', 'usr/david/foo.txt', 'usr/mitsuko/foo.txt'])
69+
```
6770

68-
.. admonition:: Note on Handling Files
71+
```{admonition} Note on Handling Files
72+
:class: note
6973
70-
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+
```
7176

72-
Argument Escape Sequences
73-
---------------------------
77+
## Argument Escape Sequences
7478

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.
7680

7781
Example usage:
7882

83+
```{eval-rst}
7984
.. click:example::
8085
8186
@click.command()
@@ -90,9 +95,11 @@ And from the command line:
9095
.. click:run::
9196
9297
invoke(touch, ['--', '-foo.txt', 'bar.txt'])
98+
```
9399

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:
95101

102+
```{eval-rst}
96103
.. click:example::
97104
98105
@click.command(context_settings={"ignore_unknown_options": True})
@@ -107,17 +114,17 @@ And from the command line:
107114
.. click:run::
108115
109116
invoke(touch, ['-foo.txt', 'bar.txt'])
117+
```
110118

119+
(environment-variables)=
111120

112-
.. _environment-variables:
113-
114-
Environment Variables
115-
---------------------
121+
## Environment Variables
116122

117-
Arguments can use environment variables. To do so, pass the name(s) of the environment variable(s) via `envvar` in ``click.argument``.
123+
Arguments can use environment variables. To do so, pass the name(s) of the environment variable(s) via `envvar` in `click.argument`.
118124

119125
Checking one environment variable:
120126

127+
```{eval-rst}
121128
.. click:example::
122129
123130
@click.command()
@@ -156,3 +163,4 @@ And from the command line:
156163
with open('hello.txt', 'w') as f:
157164
f.write('Hello World from second variable!')
158165
invoke(echo, env={'SRC_2': 'hello.txt'})
166+
```

0 commit comments

Comments
 (0)