@@ -338,9 +338,6 @@ class Cmd(cmd.Cmd):
338338 'quiet' : "Don't print nonessential feedback" ,
339339 'timing' : 'Report execution times' }
340340
341- # Override cmd's nohelp
342- nohelp = "No help on {}"
343-
344341 def __init__ (self , completekey : str = 'tab' , stdin = None , stdout = None , persistent_history_file : str = '' ,
345342 persistent_history_length : int = 1000 , startup_script : Optional [str ] = None , use_ipython : bool = False ,
346343 transcript_files : Optional [List [str ]] = None ) -> None :
@@ -431,6 +428,12 @@ def __init__(self, completekey: str = 'tab', stdin=None, stdout=None, persistent
431428 # Used to keep track of whether a continuation prompt is being displayed
432429 self .at_continuation_prompt = False
433430
431+ # The error that prints when no help information can be found
432+ self .help_error = "No help on {}"
433+
434+ # The error that prints when a non-existent command is run
435+ self .default_error = "{} is not a recognized command, alias, or macro"
436+
434437 # If this string is non-empty, then this warning message will print if a broken pipe error occurs while printing
435438 self .broken_pipe_warning = ''
436439
@@ -2060,7 +2063,8 @@ def default(self, statement: Statement) -> Optional[bool]:
20602063
20612064 return self .do_shell (statement .command_and_args )
20622065 else :
2063- sys .stderr .write ('{} is not a recognized command, alias, or macro\n ' .format (statement .command ))
2066+ err_msg = self .default_error .format (statement .command )
2067+ self .decolorized_write (sys .stderr , "{}\n " .format (err_msg ))
20642068
20652069 def pseudo_raw_input (self , prompt : str ) -> str :
20662070 """Began life as a copy of cmd's cmdloop; like raw_input but
@@ -2598,7 +2602,7 @@ def do_help(self, args: argparse.Namespace) -> None:
25982602
25992603 # If there is no help information then print an error
26002604 elif help_func is None and (func is None or not func .__doc__ ):
2601- err_msg = Cmd . nohelp .format (args .command )
2605+ err_msg = self . help_error .format (args .command )
26022606 self .decolorized_write (sys .stderr , "{}\n " .format (err_msg ))
26032607
26042608 # Otherwise delegate to cmd base class do_help()
0 commit comments