@@ -297,6 +297,9 @@ def __init__(
297297 instantiate and register all commands. If False, CommandSets
298298 must be manually installed with `register_command_set`.
299299 :param allow_clipboard: If False, cmd2 will disable clipboard interactions
300+ :param suggest_similar_command: If ``True``, ``cmd2`` will attempt to suggest the most
301+ similar command when the user types a command that does
302+ not exist. Default: ``False``.
300303 """
301304 # Check if py or ipy need to be disabled in this instance
302305 if not include_py :
@@ -404,7 +407,7 @@ def __init__(
404407 self .help_error = "No help on {}"
405408
406409 # The error that prints when a non-existent command is run
407- self .default_error = "{} is not a recognized command, alias, or macro"
410+ self .default_error = "{} is not a recognized command, alias, or macro. "
408411
409412 # If non-empty, this string will be displayed if a broken pipe error occurs
410413 self .broken_pipe_warning = ''
@@ -3092,11 +3095,10 @@ def default(self, statement: Statement) -> Optional[bool]: # type: ignore[overr
30923095 return self .do_shell (statement .command_and_args )
30933096 else :
30943097 err_msg = self .default_error .format (statement .command )
3095- if self .suggest_similar_command :
3096- suggested_command = self ._suggest_similar_command (statement .command )
3097- if suggested_command :
3098- err_msg = err_msg + ' ' + self .default_suggestion_message .format (suggested_command )
3099- # Set apply_style to False so default_error's style is not overridden
3098+ if self .suggest_similar_command and (suggested_command := self ._suggest_similar_command (statement .command )):
3099+ err_msg += f"\n { self .default_suggestion_message .format (suggested_command )} "
3100+
3101+ # Set apply_style to False so styles for default_error and default_suggestion_message are not overridden
31003102 self .perror (err_msg , apply_style = False )
31013103 return None
31023104
0 commit comments