@@ -135,6 +135,9 @@ def __subclasshook__(cls, C):
135135ALPHABETICAL_SORT_KEY = utils .norm_fold
136136NATURAL_SORT_KEY = utils .natural_keys
137137
138+ # Used as the command name placeholder in disabled command messages.
139+ COMMAND_NAME = "<COMMAND_NAME>"
140+
138141
139142def categorize (func : Union [Callable , Iterable ], category : str ) -> None :
140143 """Categorize a function.
@@ -2063,7 +2066,8 @@ def default(self, statement: Statement) -> Optional[bool]:
20632066
20642067 return self .do_shell (statement .command_and_args )
20652068 else :
2066- self .poutput ('*** {} is not a recognized command, alias, or macro\n ' .format (statement .command ))
2069+ self .perror ('*** {} is not a recognized command, alias, or macro' .format (statement .command ),
2070+ err_color = Fore .RESET , traceback_war = False )
20672071
20682072 def pseudo_raw_input (self , prompt : str ) -> str :
20692073 """Began life as a copy of cmd's cmdloop; like raw_input but
@@ -3678,6 +3682,10 @@ def disable_command(self, command: str, message_to_print: str) -> None:
36783682 Disable a command and overwrite its functions
36793683 :param command: the command being disabled
36803684 :param message_to_print: what to print when this command is run or help is called on it while disabled
3685+
3686+ The variable COMMAND_NAME can be used as a placeholder for the name of the
3687+ command being disabled.
3688+ ex: message_to_print = "{} is currently disabled".format(COMMAND_NAME)
36813689 """
36823690 import functools
36833691
@@ -3697,7 +3705,8 @@ def disable_command(self, command: str, message_to_print: str) -> None:
36973705 help_function = getattr (self , help_func_name , None ))
36983706
36993707 # Overwrite the command and help functions to print the message
3700- new_func = functools .partial (self ._report_disabled_command_usage , message_to_print = message_to_print )
3708+ new_func = functools .partial (self ._report_disabled_command_usage ,
3709+ message_to_print = message_to_print .replace (COMMAND_NAME , command ))
37013710 setattr (self , self .cmd_func_name (command ), new_func )
37023711 setattr (self , help_func_name , new_func )
37033712
@@ -3707,6 +3716,10 @@ def disable_category(self, category: str, message_to_print: str) -> None:
37073716 :param category: the category to disable
37083717 :param message_to_print: what to print when anything in this category is run or help is called on it
37093718 while disabled
3719+
3720+ The variable COMMAND_NAME can be used as a placeholder for the name of the
3721+ command being disabled.
3722+ ex: message_to_print = "{} is currently disabled".format(COMMAND_NAME)
37103723 """
37113724 all_commands = self .get_all_commands ()
37123725
@@ -3723,7 +3736,7 @@ def _report_disabled_command_usage(self, *args, message_to_print: str, **kwargs)
37233736 :param message_to_print: the message reporting that the command is disabled
37243737 :param kwargs: not used
37253738 """
3726- self .poutput (message_to_print )
3739+ self .perror (message_to_print , err_color = Fore . RESET , traceback_war = False )
37273740
37283741 def cmdloop (self , intro : Optional [str ] = None ) -> None :
37293742 """This is an outer wrapper around _cmdloop() which deals with extra features provided by cmd2.
0 commit comments