diff options
author | Kevin Van Brunt <kmvanbrunt@gmail.com> | 2019-03-10 13:44:39 -0400 |
---|---|---|
committer | Kevin Van Brunt <kmvanbrunt@gmail.com> | 2019-03-10 13:44:39 -0400 |
commit | a1afa7cc454c476280dda3201e8ed21d4fce9dfd (patch) | |
tree | 2fdb4fa7337bb94ce5ab59ad815572017261f74a /cmd2/cmd2.py | |
parent | c5872ac9ffa9047087340fe340b8a88bf2a902d6 (diff) | |
download | cmd2-git-a1afa7cc454c476280dda3201e8ed21d4fce9dfd.tar.gz |
Added function to report that a disabled command has been run.
Not adding disabled commands to the history when run.
Diffstat (limited to 'cmd2/cmd2.py')
-rw-r--r-- | cmd2/cmd2.py | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/cmd2/cmd2.py b/cmd2/cmd2.py index c9661a1a..957ebffd 100644 --- a/cmd2/cmd2.py +++ b/cmd2/cmd2.py @@ -1987,8 +1987,9 @@ class Cmd(cmd.Cmd): else: func = self.cmd_func(statement.command) if func: - # Since we have a valid command store it in the history - if statement.command not in self.exclude_from_history: + # Check to see if this command should be stored in history + if statement.command not in self.exclude_from_history \ + and statement.command not in self.disabled_commands: self.history.append(statement) stop = func(statement) @@ -3676,8 +3677,9 @@ class Cmd(cmd.Cmd): self.disabled_commands[command] = dc # Overwrite the command and help functions to print the message - setattr(self, self.cmd_func_name(command), functools.partial(self.poutput, message_to_print + '\n')) - setattr(self, help_func_name, functools.partial(self.poutput, message_to_print + '\n')) + new_func = functools.partial(self._report_disabled_command_usage, message_to_print=message_to_print) + setattr(self, self.cmd_func_name(command), new_func) + setattr(self, help_func_name, new_func) def disable_category(self, category: str, message_to_print: str) -> None: """ @@ -3696,6 +3698,16 @@ class Cmd(cmd.Cmd): if cmd_category is not None and cmd_category == category: self.disable_command(cmd_name, message_to_print) + # noinspection PyUnusedLocal + def _report_disabled_command_usage(self, *args, message_to_print: str, **kwargs) -> None: + """ + Report when a disabled command has been run or had help called on it + :param args: not used + :param message_to_print: the message reporting that the command is disabled + :param kwargs: not used + """ + self.poutput(message_to_print) + def cmdloop(self, intro: Optional[str] = None) -> None: """This is an outer wrapper around _cmdloop() which deals with extra features provided by cmd2. |