Skip to content

Commit 7078bd2

Browse files
committed
Placed default_suggestion_message on its own line.
1 parent 522ce2e commit 7078bd2

File tree

3 files changed

+7
-8
lines changed

3 files changed

+7
-8
lines changed

cmd2/cmd2.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,7 @@ def __init__(
404404
self.help_error = "No help on {}"
405405

406406
# The error that prints when a non-existent command is run
407-
self.default_error = "{} is not a recognized command, alias, or macro"
407+
self.default_error = "{} is not a recognized command, alias, or macro."
408408

409409
# If non-empty, this string will be displayed if a broken pipe error occurs
410410
self.broken_pipe_warning = ''
@@ -3092,11 +3092,10 @@ def default(self, statement: Statement) -> Optional[bool]: # type: ignore[overr
30923092
return self.do_shell(statement.command_and_args)
30933093
else:
30943094
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
3095+
if self.suggest_similar_command and (suggested_command := self._suggest_similar_command(statement.command)):
3096+
err_msg += f"\n{self.default_suggestion_message.format(suggested_command)}"
3097+
3098+
# Set apply_style to False so styles for default_error and default_suggestion_message are not overridden
31003099
self.perror(err_msg, apply_style=False)
31013100
return None
31023101

docs/api/cmd.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ cmd2.Cmd
99
.. attribute:: default_error
1010

1111
The error message displayed when a non-existent command is run.
12-
Default: ``{} is not a recognized command, alias, or macro``
12+
Default: ``{} is not a recognized command, alias, or macro.``
1313

1414
.. attribute:: help_error
1515

tests/test_cmd2.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ def test_base_error_suggest_command(base_app):
333333
old_suggest_similar_command = base_app.suggest_similar_command
334334
base_app.suggest_similar_command = True
335335
out, err = run_cmd(base_app, 'historic')
336-
assert "history" in err[0]
336+
assert "history" in err[1]
337337
finally:
338338
base_app.suggest_similar_command = old_suggest_similar_command
339339

0 commit comments

Comments
 (0)