summaryrefslogtreecommitdiff
path: root/cmd2
diff options
context:
space:
mode:
authorKevin Van Brunt <kmvanbrunt@gmail.com>2020-07-30 17:30:41 -0400
committeranselor <anselor@gmail.com>2020-08-04 13:38:08 -0400
commitbcd5c0895a17bd10e755202c77204a2db8707c42 (patch)
treea539c3bbfdd1d92c48ab39063629fd1802e853d8 /cmd2
parent11a86e5653fcf54e08ca808d4acdf2c2df4d980d (diff)
downloadcmd2-git-bcd5c0895a17bd10e755202c77204a2db8707c42.tar.gz
Added handling for disabled commands to CommandSet functions
Diffstat (limited to 'cmd2')
-rw-r--r--cmd2/cmd2.py25
1 files changed, 19 insertions, 6 deletions
diff --git a/cmd2/cmd2.py b/cmd2/cmd2.py
index 8c9d40b8..999c97cb 100644
--- a/cmd2/cmd2.py
+++ b/cmd2/cmd2.py
@@ -517,6 +517,11 @@ class Cmd(cmd.Cmd):
for method in methods:
cmd_name = method[0][len(COMMAND_FUNC_PREFIX):]
+ # Enable the command before uninstalling it to make sure we remove both
+ # the real functions and the ones used by the DisabledCommand object.
+ if cmd_name in self.disabled_commands:
+ self.enable_command(cmd_name)
+
delattr(self, COMMAND_FUNC_PREFIX + cmd_name)
if hasattr(self, COMPLETER_FUNC_PREFIX + cmd_name):
@@ -553,11 +558,15 @@ class Cmd(cmd.Cmd):
parser_args = getattr(method, constants.SUBCMD_ATTR_PARSER_ARGS, {})
# Search for the base command function and verify it has an argparser defined
- command_func = self.cmd_func(command_name)
- if command_func is None or not hasattr(command_func, constants.CMD_ATTR_ARGPARSER):
+ if command_name in self.disabled_commands:
+ command_func = self.disabled_commands[command_name].command_function
+ else:
+ command_func = self.cmd_func(command_name)
+
+ if command_func is None:
raise TypeError('Could not find command "{}" needed by subcommand: {}'
.format(command_name, str(method)))
- command_parser = getattr(command_func, constants.CMD_ATTR_ARGPARSER)
+ command_parser = getattr(command_func, constants.CMD_ATTR_ARGPARSER, None)
if command_parser is None:
raise TypeError('Could not find argparser for command "{}" needed by subcommand: {}'
.format(command_name, str(method)))
@@ -596,11 +605,15 @@ class Cmd(cmd.Cmd):
command_name = getattr(method, constants.SUBCMD_ATTR_COMMAND)
# Search for the base command function and verify it has an argparser defined
- command_func = self.cmd_func(command_name)
- if command_func is None or not hasattr(command_func, constants.CMD_ATTR_ARGPARSER):
+ if command_name in self.disabled_commands:
+ command_func = self.disabled_commands[command_name].command_function
+ else:
+ command_func = self.cmd_func(command_name)
+
+ if command_func is None:
raise TypeError('Could not find command "{}" needed by subcommand: {}'
.format(command_name, str(method)))
- command_parser = getattr(command_func, constants.CMD_ATTR_ARGPARSER)
+ command_parser = getattr(command_func, constants.CMD_ATTR_ARGPARSER, None)
if command_parser is None:
raise TypeError('Could not find argparser for command "{}" needed by subcommand: {}'
.format(command_name, str(method)))