Skip to content

Commit e21d197

Browse files
committed
Add stubs and documentation for parent methods. Fix #896
1 parent 6ab1940 commit e21d197

File tree

1 file changed

+42
-1
lines changed

1 file changed

+42
-1
lines changed

cmd2/cmd2.py

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1508,13 +1508,54 @@ def sigint_handler(self, signum: int, frame) -> None:
15081508
raise KeyboardInterrupt("Got a keyboard interrupt")
15091509

15101510
def precmd(self, statement: Statement) -> Statement:
1511-
"""Hook method executed just before the command is processed by ``onecmd()`` and after adding it to the history.
1511+
"""Hook method executed just before the command is executed by
1512+
:meth:`~cmd2.Cmd.onecmd` and after adding it to history.
15121513
15131514
:param statement: subclass of str which also contains the parsed input
15141515
:return: a potentially modified version of the input Statement object
1516+
1517+
See :meth:`~cmd2.Cmd.register_postparsing_hook` and
1518+
:meth:`~cmd2.Cmd.register_precmd_hook` for more robust ways
1519+
to run hooks before the command is executed. See
1520+
:ref:`features/hooks:Postparsing Hooks` and
1521+
:ref:`features/hooks:Precommand Hooks` for more information.
15151522
"""
15161523
return statement
15171524

1525+
def postcmd(self, stop: bool, statement: Statement) -> bool:
1526+
"""Hook method executed just after a command is executed by
1527+
:meth:`~cmd2.Cmd.onecmd`.
1528+
1529+
:param stop: return `True` to request the command loop terminate
1530+
:param statement: subclass of str which also contains the parsed input
1531+
1532+
See :meth:`~cmd2.Cmd.register_postcmd_hook` and :meth:`~cmd2.Cmd.register_cmdfinalization_hook` for more robust ways
1533+
to run hooks after the command is executed. See
1534+
:ref:`features/hooks:Postcommand Hooks` and
1535+
:ref:`features/hooks:Command Finalization Hooks` for more information.
1536+
"""
1537+
return stop
1538+
1539+
def preloop(self):
1540+
"""Hook method executed once when the :meth:`~.cmd2.Cmd.cmdloop()`
1541+
method is called.
1542+
1543+
See :meth:`~cmd2.Cmd.register_preloop_hook` for a more robust way
1544+
to run hooks before the command loop begins. See
1545+
:ref:`features/hooks:Application Lifecycle Hooks` for more information.
1546+
"""
1547+
pass
1548+
1549+
def postloop(self):
1550+
"""Hook method executed once when the :meth:`~.cmd2.Cmd.cmdloop()`
1551+
method is about to return.
1552+
1553+
See :meth:`~cmd2.Cmd.register_postloop_hook` for a more robust way
1554+
to run hooks after the command loop completes. See
1555+
:ref:`features/hooks:Application Lifecycle Hooks` for more information.
1556+
"""
1557+
pass
1558+
15181559
def parseline(self, line: str) -> Tuple[str, str, str]:
15191560
"""Parse the line into a command name and a string containing the arguments.
15201561

0 commit comments

Comments
 (0)