summaryrefslogtreecommitdiff
path: root/cmd2/cmd2.py
diff options
context:
space:
mode:
authorKevin Van Brunt <kmvanbrunt@gmail.com>2020-09-03 22:52:50 -0400
committerGitHub <noreply@github.com>2020-09-03 22:52:50 -0400
commite7bf6c193e7adb55986af730eb5bbd9facb182f7 (patch)
tree96e4fa1ac5cb57696aef2a0b454e0265dc5825c3 /cmd2/cmd2.py
parent36b0b75265942fe375545beb7d2d8a2c5f6f63c4 (diff)
parent85ad31905780b19d2c16965110eda7577c057708 (diff)
downloadcmd2-git-e7bf6c193e7adb55986af730eb5bbd9facb182f7.tar.gz
Merge pull request #990 from python-cmd2/on_registered
Added callbacks to CommandSet
Diffstat (limited to 'cmd2/cmd2.py')
-rw-r--r--cmd2/cmd2.py7
1 files changed, 5 insertions, 2 deletions
diff --git a/cmd2/cmd2.py b/cmd2/cmd2.py
index d768085a..f3a2d88d 100644
--- a/cmd2/cmd2.py
+++ b/cmd2/cmd2.py
@@ -503,7 +503,9 @@ class Cmd(cmd.Cmd):
self._installed_command_sets.append(cmdset)
self._register_subcommands(cmdset)
+ cmdset.on_registered()
except Exception:
+ cmdset.on_unregister()
for attrib in installed_attributes:
delattr(self, attrib)
if cmdset in self._installed_command_sets:
@@ -511,7 +513,7 @@ class Cmd(cmd.Cmd):
if cmdset in self._cmd_to_command_sets.values():
self._cmd_to_command_sets = \
{key: val for key, val in self._cmd_to_command_sets.items() if val is not cmdset}
- cmdset.on_unregister()
+ cmdset.on_unregistered()
raise
def _install_command_function(self, command: str, command_wrapper: Callable, context=''):
@@ -559,6 +561,7 @@ class Cmd(cmd.Cmd):
"""
if cmdset in self._installed_command_sets:
self._check_uninstallable(cmdset)
+ cmdset.on_unregister()
self._unregister_subcommands(cmdset)
methods = inspect.getmembers(
@@ -584,7 +587,7 @@ class Cmd(cmd.Cmd):
if hasattr(self, HELP_FUNC_PREFIX + cmd_name):
delattr(self, HELP_FUNC_PREFIX + cmd_name)
- cmdset.on_unregister()
+ cmdset.on_unregistered()
self._installed_command_sets.remove(cmdset)
def _check_uninstallable(self, cmdset: CommandSet):