summaryrefslogtreecommitdiff
path: root/cmd2/parsing.py
diff options
context:
space:
mode:
authorKevin Van Brunt <kmvanbrunt@gmail.com>2019-03-05 00:51:42 -0500
committerKevin Van Brunt <kmvanbrunt@gmail.com>2019-03-05 00:51:42 -0500
commitb79cc6921d9e0c2adf9f4524979411bafdec7dc5 (patch)
tree98d0705f3bf63e37d87374341ba73d1736c273bf /cmd2/parsing.py
parent04eac4bc45d5c811e2d54113a03f1ee546901e06 (diff)
downloadcmd2-git-b79cc6921d9e0c2adf9f4524979411bafdec7dc5.tar.gz
Added a shlex.split() wrapper to have a common way of calling it.
Replaced parse_quoted_string with _get_command_arg_list.
Diffstat (limited to 'cmd2/parsing.py')
-rw-r--r--cmd2/parsing.py12
1 files changed, 11 insertions, 1 deletions
diff --git a/cmd2/parsing.py b/cmd2/parsing.py
index 5ec13fb7..86227b5b 100644
--- a/cmd2/parsing.py
+++ b/cmd2/parsing.py
@@ -349,7 +349,7 @@ class StatementParser:
return []
# split on whitespace
- tokens = shlex.split(line, comments=False, posix=False)
+ tokens = StatementParser.shlex_split(line)
# custom lexing
tokens = self._split_on_punctuation(tokens)
@@ -607,6 +607,16 @@ class StatementParser:
return command, args
+ @staticmethod
+ def shlex_split(str_to_split: str) -> List[str]:
+ """
+ A wrapper around shlex.split() that uses cmd2's preferred arguments
+ This allows other classes to easily call split() the same way StatementParser does
+ :param str_to_split: the string being split
+ :return: A list of tokens
+ """
+ return shlex.split(str_to_split, comments=False, posix=False)
+
def _split_on_punctuation(self, tokens: List[str]) -> List[str]:
"""Further splits tokens from a command line using punctuation characters