summaryrefslogtreecommitdiff
path: root/cmd2/cmd2.py
diff options
context:
space:
mode:
Diffstat (limited to 'cmd2/cmd2.py')
-rw-r--r--cmd2/cmd2.py19
1 files changed, 11 insertions, 8 deletions
diff --git a/cmd2/cmd2.py b/cmd2/cmd2.py
index 65b35705..44e02005 100644
--- a/cmd2/cmd2.py
+++ b/cmd2/cmd2.py
@@ -50,7 +50,7 @@ from . import utils
from .argparse_custom import CompletionItem, DEFAULT_ARGUMENT_PARSER
from .clipboard import can_clip, get_paste_buffer, write_to_paste_buffer
from .decorators import with_argparser
-from .exceptions import Cmd2ArgparseException, EmbeddedConsoleExit, EmptyStatement
+from .exceptions import Cmd2ArgparseError, Cmd2ShlexError, EmbeddedConsoleExit, EmptyStatement
from .history import History, HistoryItem
from .parsing import StatementParser, Statement, Macro, MacroArg, shlex_split
from .rl_utils import rl_type, RlType, rl_get_point, rl_set_prompt, vt100_support, rl_make_safe_prompt, rl_warning
@@ -1599,9 +1599,8 @@ class Cmd(cmd.Cmd):
stop = False
try:
statement = self._input_line_to_statement(line)
- except (EmptyStatement, ValueError) as ex:
- if isinstance(ex, ValueError):
- # Since shlex.split() failed on syntax, let user know what's going on
+ except (EmptyStatement, Cmd2ShlexError) as ex:
+ if isinstance(ex, Cmd2ShlexError):
self.perror("Invalid syntax: {}".format(ex))
return self._run_cmdfinalization_hooks(stop, None)
@@ -1683,7 +1682,7 @@ class Cmd(cmd.Cmd):
# Stop saving command's stdout before command finalization hooks run
self.stdout.pause_storage = True
- except (Cmd2ArgparseException, EmptyStatement):
+ except (Cmd2ArgparseError, EmptyStatement):
# Don't do anything, but do allow command finalization hooks to run
pass
except Exception as ex:
@@ -1743,6 +1742,8 @@ class Cmd(cmd.Cmd):
:param line: the line being parsed
:return: the completed Statement
+ :raises: Cmd2ShlexError if a shlex error occurs (e.g. No closing quotation)
+ EmptyStatement when the resulting Statement is blank
"""
while True:
try:
@@ -1754,7 +1755,7 @@ class Cmd(cmd.Cmd):
# it's not a multiline command, but we parsed it ok
# so we are done
break
- except ValueError:
+ except Cmd2ShlexError:
# we have unclosed quotation marks, lets parse only the command
# and see if it's a multiline
statement = self.statement_parser.parse_command_only(line)
@@ -1791,7 +1792,7 @@ class Cmd(cmd.Cmd):
self._at_continuation_prompt = False
if not statement.command:
- raise EmptyStatement()
+ raise EmptyStatement
return statement
def _input_line_to_statement(self, line: str) -> Statement:
@@ -1800,6 +1801,8 @@ class Cmd(cmd.Cmd):
:param line: the line being parsed
:return: parsed command line as a Statement
+ :raises: Cmd2ShlexError if a shlex error occurs (e.g. No closing quotation)
+ EmptyStatement when the resulting Statement is blank
"""
used_macros = []
orig_line = None
@@ -1818,7 +1821,7 @@ class Cmd(cmd.Cmd):
used_macros.append(statement.command)
line = self._resolve_macro(statement)
if line is None:
- raise EmptyStatement()
+ raise EmptyStatement
else:
break