@@ -124,7 +124,7 @@ import argparse
124
124
125
125
There's a bit to unpack here, so let's walk through it. We created ` speak_parser ` , which uses the
126
126
[ argparse] ( https://docs.python.org/3/library/argparse.html ) module from the Python standard library
127
- to parse command line input from a user. There is nothing thus far that is specific to ` cmd2 ` .
127
+ to parse command line input from a user. So far, there is nothing specific to ` cmd2 ` .
128
128
129
129
There is also a new method called ` do_speak() ` . In both
130
130
[ cmd] ( https://docs.python.org/3/library/cmd.html ) and ` cmd2 ` , methods that start with ` do_ ` become
@@ -137,12 +137,12 @@ Note the `cmd2.decorators.with_argparser` decorator on the `do_speak()` method.
137
137
the user input doesn't meet the requirements defined by the argparser, then an error will be
138
138
displayed for the user.
139
139
1 . It alters our ` do_speak ` method so that instead of receiving the raw user input as a parameter,
140
- we receive the namespace from the argparser .
140
+ we receive the namespace from the argument parser .
141
141
1 . It creates a help message for us based on the argparser.
142
142
143
143
You can see in the body of the method how we use the namespace from the argparser (passed in as the
144
- variable ` args ` ). We build an array of words which we will output, honoring both the ` --piglatin `
145
- and ` --shout ` options.
144
+ variable ` args ` ). We build a list of words which we will output, honoring both the ` --piglatin ` and
145
+ ` --shout ` options.
146
146
147
147
At the end of the method, we use our ` maxrepeats ` setting as an upper limit to the number of times
148
148
we will print the output.
@@ -198,9 +198,9 @@ def __init__(self):
198
198
199
199
Shortcuts are passed to the ` cmd2 ` initializer, and if you want the built-in shortcuts of ` cmd2 ` you
200
200
have to pass them. These shortcuts are defined as a dictionary, with the key being the shortcut, and
201
- the value containing the command. When using the default shortcuts and also adding your own, it's a
202
- good idea to use the ` .update() ` method to modify the dictionary. This way if you add a shortcut
203
- that happens to already be in the default set, yours will override, and you won't get any errors at
201
+ the value containing the command. When using the default shortcuts and adding your own, it's a good
202
+ idea to use the ` .update() ` method to modify the dictionary. This way, if you add a shortcut that
203
+ happens to already be in the default set, yours will override, and you won't get any errors at
204
204
runtime.
205
205
206
206
Run your app again, and type:
@@ -209,16 +209,15 @@ Run your app again, and type:
209
209
(Cmd) shortcuts
210
210
```
211
211
212
- to see the list of all of the shortcuts, including the one for speak that we just created.
212
+ to see the list of all the shortcuts, including the one for speak that we just created.
213
213
214
214
## Multiline Commands
215
215
216
- Some use cases benefit from the ability to have commands that span more than one line. For example,
217
- you might want the ability for your user to type in a SQL command, which can often span lines and
218
- which are terminated with a semicolon. Let's add a
219
- [ multiline command] ( ../features/multiline_commands.md ) to our application. First we'll create a new
220
- command called ` orate ` . This code shows both the definition of our ` speak ` command, and the ` orate `
221
- command:
216
+ Some use cases benefit from commands that span more than one line. For example, you might want the
217
+ ability for your user to type in a SQL command, which can often span lines and which are terminated
218
+ with a semicolon. Let's add a [ multiline command] ( ../features/multiline_commands.md ) to our
219
+ application. First we'll create a new command called ` orate ` . This code shows both the definition of
220
+ our ` speak ` command, and the ` orate ` command:
222
221
223
222
``` py
224
223
@cmd2.with_argparser (speak_parser)
0 commit comments