diff options
author | kotfu <kotfu@kotfu.net> | 2018-04-23 20:41:04 -0600 |
---|---|---|
committer | kotfu <kotfu@kotfu.net> | 2018-04-23 20:41:04 -0600 |
commit | 7f7adaf2fa211e877987aef075affe2a7082dbc5 (patch) | |
tree | cc63c4b32acb1d9b6181601b47ec4a8ce9416a27 | |
parent | b3d71457e951d9d382787cb82fdf77f32951337c (diff) | |
download | cmd2-git-7f7adaf2fa211e877987aef075affe2a7082dbc5.tar.gz |
More work on multiline
-rwxr-xr-x | cmd2/cmd2.py | 8 | ||||
-rw-r--r-- | cmd2/parsing.py | 4 | ||||
-rw-r--r-- | tests/test_shlexparsing.py | 12 |
3 files changed, 15 insertions, 9 deletions
diff --git a/cmd2/cmd2.py b/cmd2/cmd2.py index 8aed075b..d9cbd2b0 100755 --- a/cmd2/cmd2.py +++ b/cmd2/cmd2.py @@ -2181,10 +2181,10 @@ class Cmd(cmd.Cmd): # raise EmptyStatement() # statement = self.parser_manager.parsed(line) # deleteme statement = self.command_parser.parseString(line) - #while statement.parsed.multilineCommand and (statement.parsed.terminator == ''): - # statement = '%s\n%s' % (statement.parsed.raw, - # self.pseudo_raw_input(self.continuation_prompt)) - # statement = self.parser_manager.parsed(statement) + while statement.multilineCommand and (statement.terminator == ''): + line = '%s\n%s' % (statement.raw, + self.pseudo_raw_input(self.continuation_prompt)) + statement = self.command_parser.parseString(line) if not statement.command: raise EmptyStatement() return statement diff --git a/cmd2/parsing.py b/cmd2/parsing.py index ec8e2e84..f4f9a6a3 100644 --- a/cmd2/parsing.py +++ b/cmd2/parsing.py @@ -180,6 +180,10 @@ class CommandParser(): # set multiline if command in self.multilineCommands: multilineCommand = command + # return no arguments if this is a "partial" command, + # i.e. we have a multiline command but no terminator yet + if not terminator: + args = '' else: multilineCommand = None diff --git a/tests/test_shlexparsing.py b/tests/test_shlexparsing.py index b9caed7c..d0907820 100644 --- a/tests/test_shlexparsing.py +++ b/tests/test_shlexparsing.py @@ -213,11 +213,13 @@ def test_has_redirect_inside_terminator(parser): assert results.args == '> inside' assert results.terminator == ';' -# def test_parse_unfinished_multiliine_command(parser): -# line = 'multiline has > inside an unfinished command' -# results = parser.parseString(line) -# assert results.multilineCommand == 'multiline' -# assert not 'args' in results +def test_parse_unfinished_multiliine_command(parser): + line = 'multiline has > inside an unfinished command' + statement = parser.parseString(line) + assert statement.multilineCommand == 'multiline' + assert not statement.args + assert not statement.terminator + def test_parse_multiline_command_ignores_redirectors_within_it(parser): line = 'multiline has > inside;' |