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

Method onecmd_plus_hooks

cmd2/cmd2.py:2873–2997  ·  view source on GitHub ↗

Top-level function called by cmdloop() to handle parsing a line and running the command and all of its hooks. :param line: command line to run :param add_to_history: If True, then add this command to history. Defaults to True. :param raise_keyboard_interrupt: if True, then K

(
        self,
        line: str,
        *,
        add_to_history: bool = True,
        raise_keyboard_interrupt: bool = False,
        py_bridge_call: bool = False,
    )

Source from the content-addressed store, hash-verified

2871 return partial_statement.command, partial_statement.args, partial_statement.command_and_args
2872
2873 def onecmd_plus_hooks(
2874 self,
2875 line: str,
2876 *,
2877 add_to_history: bool = True,
2878 raise_keyboard_interrupt: bool = False,
2879 py_bridge_call: bool = False,
2880 ) -> bool:
2881 """Top-level function called by cmdloop() to handle parsing a line and running the command and all of its hooks.
2882
2883 :param line: command line to run
2884 :param add_to_history: If True, then add this command to history. Defaults to True.
2885 :param raise_keyboard_interrupt: if True, then KeyboardInterrupt exceptions will be raised if stop isn't already
2886 True. This is used when running commands in a loop to be able to stop the whole
2887 loop and not just the current command. Defaults to False.
2888 :param py_bridge_call: This should only ever be set to True by PyBridge to signify the beginning
2889 of an app() call from Python. It is used to enable/disable the storage of the
2890 command's stdout.
2891 :return: True if running of commands should stop
2892 """
2893 import datetime
2894
2895 stop = False
2896 statement = None
2897
2898 try:
2899 # Convert the line into a Statement
2900 statement = self._input_line_to_statement(line)
2901
2902 # call the postparsing hooks
2903 postparsing_data = plugin.PostparsingData(False, statement)
2904 for postparsing_func in self._postparsing_hooks:
2905 postparsing_data = postparsing_func(postparsing_data)
2906 if postparsing_data.stop:
2907 break
2908
2909 # unpack the postparsing_data object
2910 statement = postparsing_data.statement
2911 stop = postparsing_data.stop
2912 if stop:
2913 # we should not run the command, but
2914 # we need to run the finalization hooks
2915 raise EmptyStatement # noqa: TRY301
2916
2917 redir_saved_state: utils.RedirectionSavedState | None = None
2918
2919 try:
2920 # Get sigint protection while we set up redirection
2921 with self.sigint_protection:
2922 if py_bridge_call:
2923 # Start saving command's stdout at this point
2924 self.stdout.pause_storage = False # type: ignore[attr-defined]
2925
2926 redir_saved_state = self._redirect_output(statement)
2927
2928 timestart = datetime.datetime.now(tz=datetime.timezone.utc)
2929
2930 # precommand hooks

Calls 10

_redirect_outputMethod · 0.95
precmdMethod · 0.95
onecmdMethod · 0.95
postcmdMethod · 0.95
pfeedbackMethod · 0.95
_restore_outputMethod · 0.95
perrorMethod · 0.95
pexceptMethod · 0.95