summaryrefslogtreecommitdiff
path: root/cmd2/command_definition.py
diff options
context:
space:
mode:
authorEric Lin <anselor@gmail.com>2020-06-13 12:30:33 -0400
committeranselor <anselor@gmail.com>2020-08-04 13:38:08 -0400
commitc88de7dfcfed716e81d06775b6e7929e4e01428c (patch)
treee8d2abb125ff2921f6de4607059fd7335dd70992 /cmd2/command_definition.py
parente32cccc4e599c924c3fd5f8376f7efd085f88019 (diff)
downloadcmd2-git-c88de7dfcfed716e81d06775b6e7929e4e01428c.tar.gz
add ability to remove commands and commandsets
Issue #943
Diffstat (limited to 'cmd2/command_definition.py')
-rw-r--r--cmd2/command_definition.py9
1 files changed, 8 insertions, 1 deletions
diff --git a/cmd2/command_definition.py b/cmd2/command_definition.py
index a235525d..115cef64 100644
--- a/cmd2/command_definition.py
+++ b/cmd2/command_definition.py
@@ -87,6 +87,7 @@ def register_command(cmd_func: Callable[['Cmd', Union['Statement', 'argparse.Nam
break
_UNBOUND_COMMANDS.append((cmd_name, cmd_func, cmd_completer, cmd_help))
+ return cmd_func
def with_default_category(category: str):
@@ -132,6 +133,12 @@ class CommandSet(object):
to perform an initialization requiring access to the Cmd object.
:param cmd: The cmd2 main application
- :return: None
"""
self._cmd = cmd
+
+ def on_unregister(self, cmd: 'Cmd'):
+ """
+ Called by ``cmd2.Cmd`` when a CommandSet is unregistered and removed.
+ :param cmd:
+ """
+ self._cmd = None