@@ -1987,8 +1987,9 @@ def onecmd(self, statement: Union[Statement, str]) -> bool:
19871987 else :
19881988 func = self .cmd_func (statement .command )
19891989 if func :
1990- # Since we have a valid command store it in the history
1991- if statement .command not in self .exclude_from_history :
1990+ # Check to see if this command should be stored in history
1991+ if statement .command not in self .exclude_from_history \
1992+ and statement .command not in self .disabled_commands :
19921993 self .history .append (statement )
19931994
19941995 stop = func (statement )
@@ -3676,8 +3677,9 @@ def disable_command(self, command: str, message_to_print: str) -> None:
36763677 self .disabled_commands [command ] = dc
36773678
36783679 # Overwrite the command and help functions to print the message
3679- setattr (self , self .cmd_func_name (command ), functools .partial (self .poutput , message_to_print + '\n ' ))
3680- setattr (self , help_func_name , functools .partial (self .poutput , message_to_print + '\n ' ))
3680+ new_func = functools .partial (self ._report_disabled_command_usage , message_to_print = message_to_print )
3681+ setattr (self , self .cmd_func_name (command ), new_func )
3682+ setattr (self , help_func_name , new_func )
36813683
36823684 def disable_category (self , category : str , message_to_print : str ) -> None :
36833685 """
@@ -3696,6 +3698,16 @@ def disable_category(self, category: str, message_to_print: str) -> None:
36963698 if cmd_category is not None and cmd_category == category :
36973699 self .disable_command (cmd_name , message_to_print )
36983700
3701+ # noinspection PyUnusedLocal
3702+ def _report_disabled_command_usage (self , * args , message_to_print : str , ** kwargs ) -> None :
3703+ """
3704+ Report when a disabled command has been run or had help called on it
3705+ :param args: not used
3706+ :param message_to_print: the message reporting that the command is disabled
3707+ :param kwargs: not used
3708+ """
3709+ self .poutput (message_to_print )
3710+
36993711 def cmdloop (self , intro : Optional [str ] = None ) -> None :
37003712 """This is an outer wrapper around _cmdloop() which deals with extra features provided by cmd2.
37013713
0 commit comments