diff options
author | Kevin Van Brunt <kmvanbrunt@gmail.com> | 2020-03-12 15:53:40 -0400 |
---|---|---|
committer | Kevin Van Brunt <kmvanbrunt@gmail.com> | 2020-03-12 15:53:40 -0400 |
commit | b3eafe71b400a7a48bda5a456d53a9433ef838dd (patch) | |
tree | d2b9151f48eaabefa3eb48772aa370da7f5f8a5c /cmd2/parsing.py | |
parent | d17f79428a41a5239c4fdbdf9745c294649f49e8 (diff) | |
download | cmd2-git-b3eafe71b400a7a48bda5a456d53a9433ef838dd.tar.gz |
Added Cmd2ShlexError
Diffstat (limited to 'cmd2/parsing.py')
-rwxr-xr-x | cmd2/parsing.py | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/cmd2/parsing.py b/cmd2/parsing.py index 078b1860..71582f1a 100755 --- a/cmd2/parsing.py +++ b/cmd2/parsing.py @@ -10,6 +10,7 @@ import attr from . import constants from . import utils +from .exceptions import Cmd2ShlexError def shlex_split(str_to_split: str) -> List[str]: @@ -330,7 +331,7 @@ class StatementParser: :param line: the command line being lexed :return: A list of tokens - :raises ValueError: if there are unclosed quotation marks + :raises: Cmd2ShlexError if a shlex error occurs (e.g. No closing quotation) """ # expand shortcuts and aliases @@ -341,7 +342,10 @@ class StatementParser: return [] # split on whitespace - tokens = shlex_split(line) + try: + tokens = shlex_split(line) + except ValueError as ex: + raise Cmd2ShlexError(ex) # custom lexing tokens = self.split_on_punctuation(tokens) @@ -355,7 +359,7 @@ class StatementParser: :param line: the command line being parsed :return: a new :class:`~cmd2.Statement` object - :raises ValueError: if there are unclosed quotation marks + :raises: Cmd2ShlexError if a shlex error occurs (e.g. No closing quotation) """ # handle the special case/hardcoded terminator of a blank line @@ -518,8 +522,6 @@ class StatementParser: :param rawinput: the command line as entered by the user :return: a new :class:`~cmd2.Statement` object """ - line = rawinput - # expand shortcuts and aliases line = self._expand(rawinput) |