summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CHANGELOG.md5
-rw-r--r--cmd2/cmd2.py1
-rw-r--r--cmd2/command_definition.py11
3 files changed, 15 insertions, 2 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 5c65bb8a..a22bfdf8 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,3 +1,8 @@
+## 1.3.9 (September 01, 2020)
+* Enhancements
+ * Added `on_registered()` callback to `CommandSet` class. This is called by `cmd2.Cmd` after a
+ `CommandSet` is registered and all its commands have been added to the CLI.
+
## 1.3.8 (August 28, 2020)
* Bug Fixes
* Fixed issue where subcommand added with `@as_subcommand_to` decorator did not display help
diff --git a/cmd2/cmd2.py b/cmd2/cmd2.py
index d768085a..8fd3d243 100644
--- a/cmd2/cmd2.py
+++ b/cmd2/cmd2.py
@@ -503,6 +503,7 @@ class Cmd(cmd.Cmd):
self._installed_command_sets.append(cmdset)
self._register_subcommands(cmdset)
+ cmdset.on_registered()
except Exception:
for attrib in installed_attributes:
delattr(self, attrib)
diff --git a/cmd2/command_definition.py b/cmd2/command_definition.py
index 27a044bc..3c663054 100644
--- a/cmd2/command_definition.py
+++ b/cmd2/command_definition.py
@@ -53,7 +53,7 @@ class CommandSet(object):
def __init__(self):
self._cmd = None # type: Optional[cmd2.Cmd]
- def on_register(self, cmd):
+ def on_register(self, cmd) -> None:
"""
Called by cmd2.Cmd when a CommandSet is registered. Subclasses can override this
to perform an initialization requiring access to the Cmd object.
@@ -66,7 +66,14 @@ class CommandSet(object):
else:
raise CommandSetRegistrationError('This CommandSet has already been registered')
- def on_unregister(self):
+ def on_registered(self) -> None:
+ """
+ Called by cmd2.Cmd after a CommandSet is registered and all its commands have been added
+ to the CLI. Subclasses can override this to perform custom steps.
+ """
+ pass
+
+ def on_unregister(self) -> None:
"""
Called by ``cmd2.Cmd`` when a CommandSet is unregistered and removed.