As is discussed here, I should be able to declare and register a preloop hook as follows:
class App(cmd2.Cmd):
def __init__(self, *args, *kwargs):
super().__init__(*args, **kwargs)
self.register_preloop_hook(self.myhookmethod)
def myhookmethod(self):
self.poutput("before the loop begins")
However, running the above will throw an error: TypeError: initialize_preloop must declare return a return type of 'None'. In order to fix the error, you need to provide a return type hint:
class App(cmd2.Cmd):
def __init__(self, *args, *kwargs):
super().__init__(*args, **kwargs)
self.register_preloop_hook(self.myhookmethod)
def myhookmethod(self) -> None:
self.poutput("before the loop begins")
Versions: