@@ -297,6 +297,9 @@ def __init__(
297
297
instantiate and register all commands. If False, CommandSets
298
298
must be manually installed with `register_command_set`.
299
299
: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``.
300
303
"""
301
304
# Check if py or ipy need to be disabled in this instance
302
305
if not include_py :
@@ -404,7 +407,7 @@ def __init__(
404
407
self .help_error = "No help on {}"
405
408
406
409
# 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. "
408
411
409
412
# If non-empty, this string will be displayed if a broken pipe error occurs
410
413
self .broken_pipe_warning = ''
@@ -3092,11 +3095,10 @@ def default(self, statement: Statement) -> Optional[bool]: # type: ignore[overr
3092
3095
return self .do_shell (statement .command_and_args )
3093
3096
else :
3094
3097
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
3100
3102
self .perror (err_msg , apply_style = False )
3101
3103
return None
3102
3104
0 commit comments