diff options
author | Todd Leonhardt <todd.leonhardt@gmail.com> | 2020-03-13 08:10:51 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-03-13 08:10:51 -0400 |
commit | 77e2a0fab7620d22e0fde6be7374dbbf26706fd4 (patch) | |
tree | 7596897fa233204b7c7b84c94f26c71ccaf5ad5b /cmd2/parsing.py | |
parent | 59739aa5b6f253814fb019a9e777056a6efb61ca (diff) | |
parent | a4160cfe9ab39402511c1a445f3b978099743bc9 (diff) | |
download | cmd2-git-77e2a0fab7620d22e0fde6be7374dbbf26706fd4.tar.gz |
Merge pull request #906 from python-cmd2/parsing_exception
Parsing exception
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) |