Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 17 additions & 14 deletions cmd2.py
Original file line number Diff line number Diff line change
Expand Up @@ -784,9 +784,9 @@ def _init_parser(self):
do_not_parse = self.commentGrammars | self.commentInProgress | pyparsing.quotedString
after_elements = \
pyparsing.Optional(pipe + pyparsing.SkipTo(output_parser ^ string_end, ignore=do_not_parse)('pipeTo')) + \
pyparsing.Optional(
output_parser + pyparsing.SkipTo(string_end, ignore=do_not_parse).setParseAction(lambda x: x[0].strip())(
'outputTo'))
pyparsing.Optional(output_parser +
pyparsing.SkipTo(string_end,
ignore=do_not_parse).setParseAction(lambda x: x[0].strip())('outputTo'))
if self.case_insensitive:
self.multilineCommand.setParseAction(lambda x: x[0].lower())
oneline_command.setParseAction(lambda x: x[0].lower())
Expand All @@ -796,17 +796,21 @@ def _init_parser(self):
self.blankLineTerminator = (pyparsing.lineEnd + pyparsing.lineEnd)('terminator')
self.blankLineTerminator.setResultsName('terminator')
self.blankLineTerminationParser = ((self.multilineCommand ^ oneline_command) +
pyparsing.SkipTo(self.blankLineTerminator, ignore=do_not_parse).setParseAction(
lambda x: x[0].strip())('args') + self.blankLineTerminator)('statement')
self.multilineParser = (((self.multilineCommand ^ oneline_command) + pyparsing.SkipTo(terminator_parser,
ignore=do_not_parse).setParseAction(
lambda x: x[0].strip())('args') + terminator_parser)('statement') +
pyparsing.SkipTo(self.blankLineTerminator,
ignore=do_not_parse).setParseAction(
lambda x: x[0].strip())('args') +
self.blankLineTerminator)('statement')
self.multilineParser = (((self.multilineCommand ^ oneline_command) +
pyparsing.SkipTo(terminator_parser,
ignore=do_not_parse).setParseAction(
lambda x: x[0].strip())('args') + terminator_parser)('statement') +
pyparsing.SkipTo(output_parser ^ pipe ^ string_end, ignore=do_not_parse).setParseAction(
lambda x: x[0].strip())('suffix') + after_elements)
self.multilineParser.ignore(self.commentInProgress)
self.singleLineParser = ((oneline_command + pyparsing.SkipTo(terminator_parser ^ string_end ^ pipe ^ output_parser,
ignore=do_not_parse).setParseAction(
lambda x: x[0].strip())('args'))('statement') +
self.singleLineParser = ((oneline_command +
pyparsing.SkipTo(terminator_parser ^ string_end ^ pipe ^ output_parser,
ignore=do_not_parse).setParseAction(
lambda x: x[0].strip())('args'))('statement') +
pyparsing.Optional(terminator_parser) + after_elements)
# self.multilineParser = self.multilineParser.setResultsName('multilineParser')
# self.singleLineParser = self.singleLineParser.setResultsName('singleLineParser')
Expand Down Expand Up @@ -2056,8 +2060,8 @@ def _test_transcript(self, fname, transcript):
line_num += 1
command = ''.join(command)
# Send the command into the application and capture the resulting output
stop = self.cmdapp.onecmd_plus_hooks(command)
# TODO: should act on ``stop``
# TODO: Should we get the return value and act if stop == True?
self.cmdapp.onecmd_plus_hooks(command)
result = self.outputTrap.read()
# Read the expected result from transcript
if line.startswith(self.cmdapp.prompt):
Expand Down Expand Up @@ -2089,7 +2093,6 @@ def tearDown(self):
self.outputTrap.tear_down()


#noinspection PyClassHasNoInit
class CmdResult(namedtuple('CmdResult', ['out', 'err', 'war'])):
"""Derive a class to store results from a named tuple so we can tweak dunder methods for convenience.

Expand Down