MCPcopy Index your code
hub / github.com/python-cmd2/cmd2 / _check_statement_complete

Method _check_statement_complete

cmd2/cmd2.py:3055–3083  ·  view source on GitHub ↗

Check if the given line is a complete statement. :param line: the current input string to check :return: the completed Statement :raises Cmd2ShlexError: if a shlex error occurs on a non-multiline command :raises IncompleteStatement: if more input is needed for multil

(self, line: str)

Source from the content-addressed store, hash-verified

3053 return False
3054
3055 def _check_statement_complete(self, line: str) -> Statement:
3056 """Check if the given line is a complete statement.
3057
3058 :param line: the current input string to check
3059 :return: the completed Statement
3060 :raises Cmd2ShlexError: if a shlex error occurs on a non-multiline command
3061 :raises IncompleteStatement: if more input is needed for multiline
3062 :raises EmptyStatement: if the command is blank
3063 """
3064 try:
3065 statement = self.statement_parser.parse(line)
3066
3067 # Check if we have a finished multiline command or a standard command
3068 if (statement.multiline_command and statement.terminator) or not statement.multiline_command:
3069 if not statement.command:
3070 raise EmptyStatement
3071 return statement
3072
3073 except Cmd2ShlexError:
3074 # Check if the error is occurring within a multiline command
3075 partial_statement = self.statement_parser.parse_command_only(line)
3076 if not partial_statement.multiline_command:
3077 # It's a standard command with a quoting error, raise it
3078 raise
3079
3080 # If we reached here, the statement is incomplete:
3081 # - Multiline command missing a terminator
3082 # - Multiline command with an unclosed quotation mark
3083 raise IncompleteStatement
3084
3085 def _complete_statement(self, line: str) -> Statement:
3086 """Keep accepting lines of input until the command is complete.

Callers 2

_complete_statementMethod · 0.95

Calls 2

parseMethod · 0.80
parse_command_onlyMethod · 0.80

Tested by

no test coverage detected