def cmdloop(self, intro=None):
"""This is an outer wrapper around _cmdloop() which deals with extra features provided by cmd2.
_cmdloop() provides the main loop equivalent to cmd.cmdloop(). This is a wrapper around that which deals with
the following extra features provided by cmd2:
- commands at invocation
- transcript testing
- intro banner
:param intro: str - if provided this overrides self.intro and serves as the intro banner printed once at start
"""
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 transcript testing was called for, use other arguments as transcript files
if callopts.test:
self._transcript_files = callargs
# If commands were supplied at invocation, then add them to the command queue
if callargs:
self.cmdqueue.extend(callargs)
# Always run the preloop first
self.preloop()
# If transcript-based regression testing was requested, then do that instead of the main loop
if self._transcript_files is not None:
self.run_transcript_tests(self._transcript_files)
else:
# If an intro was supplied in the method call, allow it to override the default
if intro is not None:
self.intro = intro
# Print the intro, if there is one, right after the preloop
if self.intro is not None:
self.poutput(str(self.intro) + "\n")
# And then call _cmdloop() to enter the main loop
self._cmdloop()
# Run the postloop() no matter what
self.postloop()
# noinspection PyPep8Naming
评论列表
文章目录