@@ -419,6 +419,12 @@ def __init__(self, completekey: str = 'tab', stdin=None, stdout=None, persistent
419419 # Used to keep track of whether a continuation prompt is being displayed
420420 self .at_continuation_prompt = False
421421
422+ # The error that prints when no help information can be found
423+ self .help_error = "No help on {}"
424+
425+ # The error that prints when a non-existent command is run
426+ self .default_error = "{} is not a recognized command, alias, or macro"
427+
422428 # If this string is non-empty, then this warning message will print if a broken pipe error occurs while printing
423429 self .broken_pipe_warning = ''
424430
@@ -2065,8 +2071,8 @@ def default(self, statement: Statement) -> Optional[bool]:
20652071
20662072 return self .do_shell (statement .command_and_args )
20672073 else :
2068- self . perror ( '*** {} is not a recognized command, alias, or macro' . format (statement .command ),
2069- err_color = Fore . RESET , traceback_war = False )
2074+ err_msg = self . default_error . format (statement .command )
2075+ self . decolorized_write ( sys . stderr , "{} \n " . format ( err_msg ) )
20702076
20712077 def pseudo_raw_input (self , prompt : str ) -> str :
20722078 """Began life as a copy of cmd's cmdloop; like raw_input but
@@ -2595,12 +2601,21 @@ def do_help(self, args: argparse.Namespace) -> None:
25952601 else :
25962602 # Getting help for a specific command
25972603 func = self .cmd_func (args .command )
2604+ help_func = getattr (self , HELP_FUNC_PREFIX + args .command , None )
2605+
2606+ # If the command function uses argparse, then use argparse's help
25982607 if func and hasattr (func , 'argparser' ):
25992608 completer = AutoCompleter (getattr (func , 'argparser' ), self )
26002609 tokens = [args .command ] + args .subcommand
26012610 self .poutput (completer .format_help (tokens ))
2611+
2612+ # If there is no help information then print an error
2613+ elif help_func is None and (func is None or not func .__doc__ ):
2614+ err_msg = self .help_error .format (args .command )
2615+ self .decolorized_write (sys .stderr , "{}\n " .format (err_msg ))
2616+
2617+ # Otherwise delegate to cmd base class do_help()
26022618 else :
2603- # No special behavior needed, delegate to cmd base class do_help()
26042619 super ().do_help (args .command )
26052620
26062621 def _help_menu (self , verbose : bool = False ) -> None :
@@ -3735,7 +3750,7 @@ def _report_disabled_command_usage(self, *args, message_to_print: str, **kwargs)
37353750 :param message_to_print: the message reporting that the command is disabled
37363751 :param kwargs: not used
37373752 """
3738- self .perror ( message_to_print , err_color = Fore . RESET , traceback_war = False )
3753+ self .decolorized_write ( sys . stderr , "{} \n " . format ( message_to_print ) )
37393754
37403755 def cmdloop (self , intro : Optional [str ] = None ) -> None :
37413756 """This is an outer wrapper around _cmdloop() which deals with extra features provided by cmd2.
0 commit comments