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

Method runcmds_plus_hooks

cmd2/cmd2.py:3018–3053  ·  view source on GitHub ↗

Run commands in an automated fashion from sources like text scripts or history replays. The prompt and command line for each command will be printed if echo is True. :param cmds: commands to run :param add_to_history: If True, then add these commands to history. Defaults to

(
        self,
        cmds: Iterable[HistoryItem] | Iterable[str],
        *,
        add_to_history: bool = True,
        stop_on_keyboard_interrupt: bool = False,
    )

Source from the content-addressed store, hash-verified

3016 return data.stop
3017
3018 def runcmds_plus_hooks(
3019 self,
3020 cmds: Iterable[HistoryItem] | Iterable[str],
3021 *,
3022 add_to_history: bool = True,
3023 stop_on_keyboard_interrupt: bool = False,
3024 ) -> bool:
3025 """Run commands in an automated fashion from sources like text scripts or history replays.
3026
3027 The prompt and command line for each command will be printed if echo is True.
3028
3029 :param cmds: commands to run
3030 :param add_to_history: If True, then add these commands to history. Defaults to True.
3031 :param stop_on_keyboard_interrupt: if True, then stop running contents of cmds if Ctrl-C is pressed instead of moving
3032 to the next command in the list. This is used when the commands are part of a
3033 group, like a text script, which should stop upon Ctrl-C. Defaults to False.
3034 :return: True if running of commands should stop
3035 """
3036 for line in cmds:
3037 if isinstance(line, HistoryItem):
3038 line = line.raw # noqa: PLW2901
3039
3040 if self.echo:
3041 self.poutput(f"{self.prompt}{line}")
3042
3043 try:
3044 if self.onecmd_plus_hooks(
3045 line, add_to_history=add_to_history, raise_keyboard_interrupt=stop_on_keyboard_interrupt
3046 ):
3047 return True
3048 except KeyboardInterrupt as ex:
3049 if stop_on_keyboard_interrupt:
3050 self.perror(ex)
3051 break
3052
3053 return False
3054
3055 def _check_statement_complete(self, line: str) -> Statement:
3056 """Check if the given line is a complete statement.

Callers 6

_cmdloopMethod · 0.95
do_historyMethod · 0.95
do_run_scriptMethod · 0.95
test_echoFunction · 0.95
test_runcmds_plus_hooksFunction · 0.80

Calls 3

poutputMethod · 0.95
onecmd_plus_hooksMethod · 0.95
perrorMethod · 0.95

Tested by 3

test_echoFunction · 0.76
test_runcmds_plus_hooksFunction · 0.64