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
@@ -31,11 +36,11 @@ command which might have its own argument parsing.
31
36
32
37
## Argument Parsing
33
38
34
-
For each command in the `cmd2` subclass which requires argument parsing, create a unique instance of
35
-
`argparse.ArgumentParser()` which can parse the input appropriately for the command. Then decorate
36
-
the command method with the `@with_argparser` decorator, passing the argument parser as the first
37
-
parameter to the decorator. This changes the second argument to the command method, which will
38
-
contain the results of `ArgumentParser.parse_args()`.
39
+
For each command in the `cmd2.Cmd` subclass which requires argument parsing, create a unique
40
+
instance of `argparse.ArgumentParser()` which can parse the input appropriately for the command.
41
+
Then decorate the command method with the `@with_argparser` decorator, passing the argument parser
42
+
as the first parameter to the decorator. This changes the second argument to the command method,
43
+
which will contain the results of `ArgumentParser.parse_args()`.
39
44
40
45
Here's what it looks like:
41
46
@@ -65,8 +70,8 @@ def do_speak(self, opts):
65
70
66
71
`cmd2` sets the `prog` variable in the argument parser based on the name of the method it is decorating. This will override anything you specify in `prog` variable when creating the argument parser.
67
72
68
-
As of the 3.0.0 release, `cmd2` sets `prog` when the instance-specific parser is created, which is
69
-
later than it did previously.
73
+
As of the 3.0.0 release, `cmd2` sets `prog` when the instance-specific parser is created, which is
@@ -94,7 +99,7 @@ the `help tag` command displays:
94
99
```text
95
100
usage: tag [-h] tag content [content ...]
96
101
97
-
create an HTML tag
102
+
Create an HTML tag
98
103
99
104
positional arguments:
100
105
tag tag
@@ -168,13 +173,13 @@ This command cannot generate tags with no content, like <br/>
168
173
169
174
!!! warning
170
175
171
-
If a command **foo** is decorated with one of cmd2's argparse decorators, then **help_foo** will not be invoked when `help foo` is called. The [argparse](https://docs.python.org/3/library/argparse.html) module provides a rich API which can be used to tweak every aspect of the displayed help and we encourage `cmd2` developers to utilize that.
176
+
If a command **foo** is decorated with `cmd2`'s `with_argparse` decorator, then **help_foo** will not be invoked when `help foo` is called. The [argparse](https://docs.python.org/3/library/argparse.html) module provides a rich API which can be used to tweak every aspect of the displayed help and we encourage `cmd2` developers to utilize that.
172
177
173
178
## Argument List
174
179
175
180
The default behavior of `cmd2` is to pass the user input directly to your `do_*` methods as a
176
-
string. The object passed to your method is actually a `Statement` object, which has additional
177
-
attributes that may be helpful, including `arg_list` and `argv`:
181
+
string. The object passed to your method is actually a [Statement][cmd2.Statement] object, which has
182
+
additional attributes that may be helpful, including `arg_list` and `argv`:
178
183
179
184
```py
180
185
classCmdLineApp(cmd2.Cmd):
@@ -200,8 +205,8 @@ class CmdLineApp(cmd2.Cmd):
200
205
201
206
If you don't want to access the additional attributes on the string passed to your `do_*` method you
202
207
can still have `cmd2` apply shell parsing rules to the user input and pass you a list of arguments
203
-
instead of a string. Apply the `@with_argument_list` decorator to those methods that should receive
204
-
an argument list instead of a string:
208
+
instead of a string. Apply the [@with_argument_list][cmd2.with_argument_list] decorator to those
209
+
methods that should receive an argument list instead of a string:
0 commit comments