Skip to content

Commit

Permalink
Placed default_suggestion_message on its own line.
Browse files Browse the repository at this point in the history
  • Loading branch information
kmvanbrunt committed Sep 24, 2024
1 parent 522ce2e commit 7078bd2
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 8 deletions.
11 changes: 5 additions & 6 deletions cmd2/cmd2.py
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ def __init__(
self.help_error = "No help on {}"

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

# If non-empty, this string will be displayed if a broken pipe error occurs
self.broken_pipe_warning = ''
Expand Down Expand Up @@ -3092,11 +3092,10 @@ def default(self, statement: Statement) -> Optional[bool]: # type: ignore[overr
return self.do_shell(statement.command_and_args)
else:
err_msg = self.default_error.format(statement.command)
if self.suggest_similar_command:
suggested_command = self._suggest_similar_command(statement.command)
if suggested_command:
err_msg = err_msg + ' ' + self.default_suggestion_message.format(suggested_command)
# Set apply_style to False so default_error's style is not overridden
if self.suggest_similar_command and (suggested_command := self._suggest_similar_command(statement.command)):
err_msg += f"\n{self.default_suggestion_message.format(suggested_command)}"

# Set apply_style to False so styles for default_error and default_suggestion_message are not overridden
self.perror(err_msg, apply_style=False)
return None

Expand Down
2 changes: 1 addition & 1 deletion docs/api/cmd.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ cmd2.Cmd
.. attribute:: default_error

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

.. attribute:: help_error

Expand Down
2 changes: 1 addition & 1 deletion tests/test_cmd2.py
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ def test_base_error_suggest_command(base_app):
old_suggest_similar_command = base_app.suggest_similar_command
base_app.suggest_similar_command = True
out, err = run_cmd(base_app, 'historic')
assert "history" in err[0]
assert "history" in err[1]
finally:
base_app.suggest_similar_command = old_suggest_similar_command

Expand Down

0 comments on commit 7078bd2

Please sign in to comment.