@@ -134,6 +134,9 @@ def __subclasshook__(cls, C):
134134ALPHABETICAL_SORT_KEY = utils .norm_fold
135135NATURAL_SORT_KEY = utils .natural_keys
136136
137+ # Used as the command name placeholder in disabled command messages.
138+ COMMAND_NAME = "<COMMAND_NAME>"
139+
137140
138141def categorize (func : Union [Callable , Iterable ], category : str ) -> None :
139142 """Categorize a function.
@@ -2054,7 +2057,8 @@ def default(self, statement: Statement) -> Optional[bool]:
20542057
20552058 return self .do_shell (statement .command_and_args )
20562059 else :
2057- self .poutput ('*** {} is not a recognized command, alias, or macro\n ' .format (statement .command ))
2060+ self .perror ('*** {} is not a recognized command, alias, or macro' .format (statement .command ),
2061+ err_color = Fore .RESET , traceback_war = False )
20582062
20592063 def pseudo_raw_input (self , prompt : str ) -> str :
20602064 """Began life as a copy of cmd's cmdloop; like raw_input but
@@ -3661,6 +3665,10 @@ def disable_command(self, command: str, message_to_print: str) -> None:
36613665 Disable a command and overwrite its functions
36623666 :param command: the command being disabled
36633667 :param message_to_print: what to print when this command is run or help is called on it while disabled
3668+
3669+ The variable COMMAND_NAME can be used as a placeholder for the name of the
3670+ command being disabled.
3671+ ex: message_to_print = "{} is currently disabled".format(COMMAND_NAME)
36643672 """
36653673 import functools
36663674
@@ -3680,7 +3688,8 @@ def disable_command(self, command: str, message_to_print: str) -> None:
36803688 help_function = getattr (self , help_func_name , None ))
36813689
36823690 # Overwrite the command and help functions to print the message
3683- new_func = functools .partial (self ._report_disabled_command_usage , message_to_print = message_to_print )
3691+ new_func = functools .partial (self ._report_disabled_command_usage ,
3692+ message_to_print = message_to_print .replace (COMMAND_NAME , command ))
36843693 setattr (self , self .cmd_func_name (command ), new_func )
36853694 setattr (self , help_func_name , new_func )
36863695
@@ -3690,6 +3699,10 @@ def disable_category(self, category: str, message_to_print: str) -> None:
36903699 :param category: the category to disable
36913700 :param message_to_print: what to print when anything in this category is run or help is called on it
36923701 while disabled
3702+
3703+ The variable COMMAND_NAME can be used as a placeholder for the name of the
3704+ command being disabled.
3705+ ex: message_to_print = "{} is currently disabled".format(COMMAND_NAME)
36933706 """
36943707 all_commands = self .get_all_commands ()
36953708
@@ -3706,7 +3719,7 @@ def _report_disabled_command_usage(self, *args, message_to_print: str, **kwargs)
37063719 :param message_to_print: the message reporting that the command is disabled
37073720 :param kwargs: not used
37083721 """
3709- self .poutput (message_to_print )
3722+ self .perror (message_to_print , err_color = Fore . RESET , traceback_war = False )
37103723
37113724 def cmdloop (self , intro : Optional [str ] = None ) -> None :
37123725 """This is an outer wrapper around _cmdloop() which deals with extra features provided by cmd2.
0 commit comments