Skip to content

Commit 91bc999

Browse files
authored
Merge pull request #249 from python-cmd2/arglist
decorator changes for replacing optparse with argparse
2 parents 6895dea + 1da9045 commit 91bc999

20 files changed

+595
-660
lines changed

CHANGELOG.md

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,32 @@
22
* Bug Fixes
33
* Fixed unit tests on Python 3.7 due to changes in how re.escape() behaves in Python 3.7
44
* Enhancements
5-
* Added new **with_argument_parser** decorator for argparse-based argument parsing of command arguments
6-
* This replaces the old **options** decorator for optparse-based argument parsing
7-
* The old decorator is still present for now, but should be considered *deprecated* and will eventually be removed
8-
* See the **Argument Processing** section of the documentation for more information
9-
* Alternatively, see the **argparse_example.py** example
5+
* Three new decorators for **do_*** commands to make argument parsing easier
6+
* **with_argument_list** decorator to change argument type from str to List[str]
7+
* **do_*** commands get a single argument which is a list of strings, as pre-parsed by shlex.split()
8+
* **with_argument_parser** decorator for strict argparse-based argument parsing of command arguments
9+
* **do_*** commands get a single argument which is the output of argparse.parse_args()
10+
* **with_argparser_and_unknown_args** decorator for argparse-based argument parsing, but allowing unknown args
11+
* **do_*** commands get two arguments, the output of argparse.parse_known_args()
12+
* See the **Argument Processing** section of the documentation for more information on these decorators
13+
* Alternatively, see the **argparse_example.py** and **arg_print.py** examples
14+
* The **__relative_load** command is now hidden from the help menu by default
15+
* This command is not intended to be called from the command line, only from within scripts
16+
* The **set** command now has an additional **-a/--all** option to also display read-only settings
17+
* The **history** command can now run, edit, and save prior commands, in addition to the prior behavior of displaying prior commands.
18+
* Commands Removed
19+
* The **cmdenvironment** has been removed and its functionality incorporated into the **-a/--all** argument to **set**
20+
* The **show** command has been removed. Its functionality has always existing within **set** and continues to do so
21+
* The **save** command has been removed. The capability to save prior commands is now part of the **history** command.
22+
* The **run** command has been removed. The capability to run prior commands is now part of the **history** command.
23+
* Other changes
24+
* The **edit** command no longer allows you to edit prior commands. The capability to edit prior commands is now part of the **history** command. The **edit** command still allows you to edit arbitrary files.
25+
* the **autorun_on_edit** setting has been removed.
26+
* Deprecations
27+
* The old **options** decorator for optparse-based argument parsing is now *deprecated*
28+
* The old decorator is still present for now, but will eventually be removed in a future release
29+
* ``cmd2`` no longer includes **optparse.make_option** so if your app needs it you need to import it directly from optparse
30+
1031

1132
## 0.7.9 (January 4, 2018)
1233

README.md

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,13 @@ Instructions for implementing each feature follow.
7070
- Searchable command history
7171

7272
All commands will automatically be tracked in the session's history, unless the command is listed in Cmd's excludeFromHistory attribute.
73-
The history is accessed through the `history`, `list`, and `run` commands.
73+
The history is accessed through the `history` command.
7474
If you wish to exclude some of your custom commands from the history, append their names
7575
to the list at `Cmd.ExcludeFromHistory`.
7676

7777
- Load commands from file, save to file, edit commands in file
7878

79-
Type `help load`, `help save`, `help edit` for details.
79+
Type `help load`, `help history` for details.
8080

8181
- Multi-line commands
8282

@@ -105,7 +105,7 @@ Instructions for implementing each feature follow.
105105
argparser.add_argument('-s', '--shout', action='store_true', help='N00B EMULATION MODE')
106106
argparser.add_argument('words', nargs='+', help='words to say')
107107
@with_argument_parser(argparser)
108-
def do_speak(self, cmdline, args=None):
108+
def do_speak(self, args):
109109
"""Repeats what you tell me to."""
110110
words = []
111111
for word in args.words:
@@ -175,7 +175,7 @@ class CmdLineApp(Cmd):
175175
argparser.add_argument('-r', '--repeat', type=int, help='output [n] times')
176176
argparser.add_argument('words', nargs='+', help='words to say')
177177
@with_argument_parser(argparser)
178-
def do_speak(self, cmdline, opts=None):
178+
def do_speak(self, args):
179179
"""Repeats what you tell me to."""
180180
words = []
181181
for word in args.words:
@@ -196,7 +196,7 @@ class CmdLineApp(Cmd):
196196
argparser.add_argument('-r', '--repeat', type=int, help='how many times to repeat')
197197
argparser.add_argument('words', nargs='+', help='words to say')
198198
@with_argument_parser(argparser)
199-
def do_mumble(self, cmdline, args=None):
199+
def do_mumble(self, args):
200200
"""Mumbles what you tell me to."""
201201
repetitions = args.repeat or 1
202202
for i in range(min(repetitions, self.maxrepeats)):
@@ -236,7 +236,6 @@ example/transcript_regex.txt:
236236
# regexes on prompts just make the trailing space obvious
237237
(Cmd) set
238238
abbrev: True
239-
autorun_on_edit: False
240239
colors: /(True|False)/
241240
continuation_prompt: >/ /
242241
debug: False

0 commit comments

Comments
 (0)