From 6c939fb0fffd076b4471591fda79f85db2aab460 Mon Sep 17 00:00:00 2001 From: Eric Lin Date: Fri, 7 Aug 2020 18:17:14 -0400 Subject: Will now traverse down CommandSet inheritance tree to find all leaf descendants. 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 --- cmd2/command_definition.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'cmd2/command_definition.py') 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): """ -- cgit v1.2.1