5050from .argparse_custom import CompletionItem , DEFAULT_ARGUMENT_PARSER
5151from .clipboard import can_clip , get_paste_buffer , write_to_paste_buffer
5252from .decorators import with_argparser
53- from .exceptions import Cmd2ArgparseException , EmbeddedConsoleExit , EmptyStatement
53+ from .exceptions import Cmd2ArgparseError , Cmd2ShlexError , EmbeddedConsoleExit , EmptyStatement
5454from .history import History , HistoryItem
5555from .parsing import StatementParser , Statement , Macro , MacroArg , shlex_split
5656from .rl_utils import rl_type , RlType , rl_get_point , rl_set_prompt , vt100_support , rl_make_safe_prompt , rl_warning
@@ -1599,9 +1599,8 @@ def onecmd_plus_hooks(self, line: str, *, add_to_history: bool = True, py_bridge
15991599 stop = False
16001600 try :
16011601 statement = self ._input_line_to_statement (line )
1602- except (EmptyStatement , ValueError ) as ex :
1603- if isinstance (ex , ValueError ):
1604- # Since shlex.split() failed on syntax, let user know what's going on
1602+ except (EmptyStatement , Cmd2ShlexError ) as ex :
1603+ if isinstance (ex , Cmd2ShlexError ):
16051604 self .perror ("Invalid syntax: {}" .format (ex ))
16061605 return self ._run_cmdfinalization_hooks (stop , None )
16071606
@@ -1683,7 +1682,7 @@ def onecmd_plus_hooks(self, line: str, *, add_to_history: bool = True, py_bridge
16831682 # Stop saving command's stdout before command finalization hooks run
16841683 self .stdout .pause_storage = True
16851684
1686- except (Cmd2ArgparseException , EmptyStatement ):
1685+ except (Cmd2ArgparseError , EmptyStatement ):
16871686 # Don't do anything, but do allow command finalization hooks to run
16881687 pass
16891688 except Exception as ex :
@@ -1743,6 +1742,8 @@ def _complete_statement(self, line: str) -> Statement:
17431742
17441743 :param line: the line being parsed
17451744 :return: the completed Statement
1745+ :raises: Cmd2ShlexError if a shlex error occurs (e.g. No closing quotation)
1746+ EmptyStatement when the resulting Statement is blank
17461747 """
17471748 while True :
17481749 try :
@@ -1754,7 +1755,7 @@ def _complete_statement(self, line: str) -> Statement:
17541755 # it's not a multiline command, but we parsed it ok
17551756 # so we are done
17561757 break
1757- except ValueError :
1758+ except Cmd2ShlexError :
17581759 # we have unclosed quotation marks, lets parse only the command
17591760 # and see if it's a multiline
17601761 statement = self .statement_parser .parse_command_only (line )
@@ -1791,7 +1792,7 @@ def _complete_statement(self, line: str) -> Statement:
17911792 self ._at_continuation_prompt = False
17921793
17931794 if not statement .command :
1794- raise EmptyStatement ()
1795+ raise EmptyStatement
17951796 return statement
17961797
17971798 def _input_line_to_statement (self , line : str ) -> Statement :
@@ -1800,6 +1801,8 @@ def _input_line_to_statement(self, line: str) -> Statement:
18001801
18011802 :param line: the line being parsed
18021803 :return: parsed command line as a Statement
1804+ :raises: Cmd2ShlexError if a shlex error occurs (e.g. No closing quotation)
1805+ EmptyStatement when the resulting Statement is blank
18031806 """
18041807 used_macros = []
18051808 orig_line = None
@@ -1818,7 +1821,7 @@ def _input_line_to_statement(self, line: str) -> Statement:
18181821 used_macros .append (statement .command )
18191822 line = self ._resolve_macro (statement )
18201823 if line is None :
1821- raise EmptyStatement ()
1824+ raise EmptyStatement
18221825 else :
18231826 break
18241827
0 commit comments