summaryrefslogtreecommitdiff
path: root/cmd2/command_definition.py
diff options
context:
space:
mode:
authorKevin Van Brunt <kmvanbrunt@gmail.com>2020-09-03 11:14:15 -0400
committerKevin Van Brunt <kmvanbrunt@gmail.com>2020-09-03 11:14:15 -0400
commit68c7750765ba9a4035775a5f46f8b37339935135 (patch)
treeec19ed703cfdcecf0bb0c4976ea377a4b0fb689c /cmd2/command_definition.py
parent72fc6bf105f4b712d5a6f991746fd2f9084893fc (diff)
downloadcmd2-git-68c7750765ba9a4035775a5f46f8b37339935135.tar.gz
Added CommandSet.on_unregistered()
Diffstat (limited to 'cmd2/command_definition.py')
-rw-r--r--cmd2/command_definition.py21
1 files changed, 14 insertions, 7 deletions
diff --git a/cmd2/command_definition.py b/cmd2/command_definition.py
index 3c663054..64adaada 100644
--- a/cmd2/command_definition.py
+++ b/cmd2/command_definition.py
@@ -55,8 +55,9 @@ class CommandSet(object):
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.
+ Called by cmd2.Cmd as the first step to registering a CommandSet. The commands defined in this class have
+ not be added to the CLI object at this point. Subclasses can override this to perform any initialization
+ requiring access to the Cmd object (e.g. configure commands and their parsers based on CLI state data).
:param cmd: The cmd2 main application
:type cmd: cmd2.Cmd
@@ -68,16 +69,22 @@ class CommandSet(object):
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.
+ 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 related to the newly added commands (e.g. setting
+ them to a disabled state).
"""
pass
def on_unregister(self) -> None:
"""
- Called by ``cmd2.Cmd`` when a CommandSet is unregistered and removed.
+ Called by ``cmd2.Cmd`` as the first step to unregistering a CommandSet. Subclasses can override this to
+ perform any cleanup steps which require their commands being registered in the CLI.
+ """
+ pass
- :param cmd:
- :type cmd: cmd2.Cmd
+ def on_unregistered(self) -> None:
+ """
+ Called by ``cmd2.Cmd`` after a CommandSet has been unregistered and all its commands removed from the CLI.
+ Subclasses can override this to perform remaining cleanup steps.
"""
self._cmd = None