Skip to content

Commit 8e52a0e

Browse files
committed
Placed default_suggestion_message on its own line.
1 parent 522ce2e commit 8e52a0e

File tree

3 files changed

+12
-11
lines changed

3 files changed

+12
-11
lines changed

cmd2/cmd2.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -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

docs/api/cmd.rst

Lines changed: 3 additions & 4 deletions
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

@@ -75,6 +75,5 @@ cmd2.Cmd
7575

7676
.. attribute:: suggest_similar_command
7777

78-
If ``True``, ``cmd2`` will suggest the most similar command when the user
79-
types a command that does not exist.
80-
Default: ``False``.
78+
If ``True``, ``cmd2`` will attempt to suggest the most similar command
79+
when the user types a command that does not exist. Default: ``False``.

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)