diff options
author | Todd Leonhardt <todd.leonhardt@gmail.com> | 2017-03-04 18:44:00 -0500 |
---|---|---|
committer | Todd Leonhardt <todd.leonhardt@gmail.com> | 2017-03-04 18:44:00 -0500 |
commit | 57ce8cc24a44a035ae1830ba6e7d5faf9f4bf95f (patch) | |
tree | 582673ffc8e5c26d1026a05a8dfb34cd998ce1b6 /cmd2.py | |
parent | 51ed730e452caa646adc1c1e9147aa42813cda91 (diff) | |
download | cmd2-git-57ce8cc24a44a035ae1830ba6e7d5faf9f4bf95f.tar.gz |
Added info to CHANGES.rst on what bugs have been fixed so far this release.
Fixed a bug where the allow_cli_args attribute wasn't properly preventing OptParse from prasing the args looking for "-t" or "--test" for transcript testing.
Added an example of using Argparse with cmd2.
Diffstat (limited to 'cmd2.py')
-rwxr-xr-x | cmd2.py | 22 |
1 files changed, 14 insertions, 8 deletions
@@ -566,13 +566,14 @@ class Cmd(cmd.Cmd): timing Report execution times ''') - def __init__(self, completekey='tab', stdin=None, stdout=None, use_ipython=False): + def __init__(self, completekey='tab', stdin=None, stdout=None, use_ipython=False, transcript_files=None): """An easy but powerful framework for writing line-oriented command interpreters, extends Python's cmd package. :param completekey: str - (optional) readline name of a completion key, default to Tab :param stdin: (optional) alternate input file object, if not specified, sys.stdin is used :param stdout: (optional) alternate output file object, if not specified, sys.stdout is used :param use_ipython: (optional) should the "ipy" command be included for an embedded IPython shell + :param transcript_files: str - (optional) allows running transcript tests when allow_cli_args is False """ # If use_ipython is False, make sure the do_ipy() method doesn't exit if not use_ipython: @@ -592,6 +593,7 @@ class Cmd(cmd.Cmd): if fname.startswith('do_')] self._init_parser() self._temp_filename = None + self._transcript_files = transcript_files def poutput(self, msg): """Convenient shortcut for self.stdout.write(); adds newline if necessary.""" @@ -1491,13 +1493,17 @@ Script should contain one command per line, just like command would be typed in return self._STOP_AND_EXIT def cmdloop(self, intro=None): - parser = optparse.OptionParser() - parser.add_option('-t', '--test', dest='test', - action="store_true", - help='Test against transcript(s) in FILE (wildcards OK)') - (callopts, callargs) = parser.parse_args() - if callopts.test: - self.runTranscriptTests(callargs) + if self.allow_cli_args: + parser = optparse.OptionParser() + parser.add_option('-t', '--test', dest='test', + action="store_true", + help='Test against transcript(s) in FILE (wildcards OK)') + (callopts, callargs) = parser.parse_args() + if callopts.test: + self._transcript_files = callargs + + if self._transcript_files is not None: + self.runTranscriptTests(self._transcript_files) else: # Always run the preloop first self.preloop() |