diff options
author | Kevin Van Brunt <kmvanbrunt@gmail.com> | 2019-03-05 00:51:42 -0500 |
---|---|---|
committer | Kevin Van Brunt <kmvanbrunt@gmail.com> | 2019-03-05 00:51:42 -0500 |
commit | b79cc6921d9e0c2adf9f4524979411bafdec7dc5 (patch) | |
tree | 98d0705f3bf63e37d87374341ba73d1736c273bf /cmd2/parsing.py | |
parent | 04eac4bc45d5c811e2d54113a03f1ee546901e06 (diff) | |
download | cmd2-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.py | 12 |
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 |