summaryrefslogtreecommitdiff
path: root/cmd2/command_definition.py
diff options
context:
space:
mode:
authorEric Lin <anselor@gmail.com>2020-08-07 18:17:14 -0400
committeranselor <anselor@gmail.com>2020-08-10 11:28:29 -0400
commit6c939fb0fffd076b4471591fda79f85db2aab460 (patch)
treec511a3d549d4fcbbc3073a395f3e475a8369c208 /cmd2/command_definition.py
parent267434118955c2edfc59042d4a8c9515f63ef719 (diff)
downloadcmd2-git-6c939fb0fffd076b4471591fda79f85db2aab460.tar.gz
Will now traverse down CommandSet inheritance tree to find all leaf descendants.1.3.2
CommandSet now has a check to ensure it is only registered with one cmd2.Cmd instance at a time. Adds function to find command set by type and by command name
Diffstat (limited to 'cmd2/command_definition.py')
-rw-r--r--cmd2/command_definition.py6
1 files changed, 5 insertions, 1 deletions
diff --git a/cmd2/command_definition.py b/cmd2/command_definition.py
index 1858c80b..22d8915e 100644
--- a/cmd2/command_definition.py
+++ b/cmd2/command_definition.py
@@ -6,6 +6,7 @@ import functools
from typing import Callable, Iterable, Optional, Type
from .constants import COMMAND_FUNC_PREFIX
+from .exceptions import CommandSetRegistrationError
# Allows IDEs to resolve types without impacting imports at runtime, breaking circular dependency issues
try: # pragma: no cover
@@ -92,7 +93,10 @@ class CommandSet(object):
:param cmd: The cmd2 main application
:type cmd: cmd2.Cmd
"""
- self._cmd = cmd
+ if self._cmd is None:
+ self._cmd = cmd
+ else:
+ raise CommandSetRegistrationError('This CommandSet has already been registered')
def on_unregister(self, cmd):
"""