summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkotfu <kotfu@kotfu.net>2018-08-08 20:39:05 -0600
committerkotfu <kotfu@kotfu.net>2018-08-08 20:39:05 -0600
commitad09ee3d3bd87c3dddefa890f8dad03bcb4c143c (patch)
tree1d5d3a5beb53841b5e5345df49b396638c60e9b7
parentc4f8870b9556896af086f6374181dafa75a2d1ee (diff)
downloadcmd2-git-ad09ee3d3bd87c3dddefa890f8dad03bcb4c143c.tar.gz
parse_command_only now appropriately sets multiline_command
-rw-r--r--cmd2/parsing.py15
-rw-r--r--tests/test_parsing.py10
2 files changed, 21 insertions, 4 deletions
diff --git a/cmd2/parsing.py b/cmd2/parsing.py
index 475554b0..b67cef10 100644
--- a/cmd2/parsing.py
+++ b/cmd2/parsing.py
@@ -407,8 +407,8 @@ class StatementParser:
"""Partially parse input into a Statement object.
The command is identified, and shortcuts and aliases are expanded.
- Terminators, multiline commands, and output redirection are not
- parsed.
+ Multiline commands are identified, but terminators and output
+ redirection are not parsed.
This method is used by tab completion code and therefore must not
generate an exception if there are unclosed quotes.
@@ -420,8 +420,8 @@ class StatementParser:
- args
Different from parse(), this method does not remove redundant whitespace
- within statement.args. It does however, ensure args does not have leading
- or trailing whitespace.
+ within statement.args. It does however, ensure args does not have
+ leading or trailing whitespace.
"""
# expand shortcuts and aliases
line = self._expand(rawinput)
@@ -447,6 +447,12 @@ class StatementParser:
if not command or not args:
args = None
+ # set multiline
+ if command in self.multiline_commands:
+ multiline_command = command
+ else:
+ multiline_command = None
+
# build the statement
# string representation of args must be an empty string instead of
# None for compatibility with standard library cmd
@@ -454,6 +460,7 @@ class StatementParser:
raw=rawinput,
command=command,
args=args,
+ multiline_command=multiline_command,
)
return statement
diff --git a/tests/test_parsing.py b/tests/test_parsing.py
index 589b6e7f..de4c637e 100644
--- a/tests/test_parsing.py
+++ b/tests/test_parsing.py
@@ -601,6 +601,16 @@ def test_parse_command_only_none(parser, line):
assert statement.args is None
assert statement == ''
+def test_parse_command_only_multiline(parser):
+ line = 'multiline with partially "open quotes and no terminator'
+ statement = parser.parse_command_only(line)
+ assert statement.command == 'multiline'
+ assert statement.multiline_command == 'multiline'
+ assert statement.args == 'with partially "open quotes and no terminator'
+ assert statement == statement.args
+ assert statement.command_and_args == line
+
+
def test_statement_initialization(parser):
string = 'alias'
statement = cmd2.Statement(string)