Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
## 0.9.3 (TBD, 2018)
## 0.9.3 (July TBD, 2018)
* Bug Fixes
* Fixed bug when StatementParser ``__init__()`` was called with ``terminators`` equal to ``None``
* Fixed bug when ``Cmd.onecmd()`` was called with a raw ``str``

## 0.9.2 (June 28, 2018)
* Bug Fixes
Expand Down
9 changes: 7 additions & 2 deletions cmd2/cmd2.py
Original file line number Diff line number Diff line change
Expand Up @@ -1901,14 +1901,19 @@ def _func_named(self, arg: str) -> str:
result = target
return result

def onecmd(self, statement: Statement) -> Optional[bool]:
def onecmd(self, statement: Union[Statement, str]) -> Optional[bool]:
""" This executes the actual do_* method for a command.

If the command provided doesn't exist, then it executes _default() instead.

:param statement: Command - a parsed command from the input stream
:param statement: Command - intended to be a Statement instance parsed command from the input stream,
alternative acceptance of a str is present only for backward compatibility with cmd
:return: a flag indicating whether the interpretation of commands should stop
"""
# For backwards compatibility with cmd, allow a str to be passed in
if not isinstance(statement, Statement):
statement = self._complete_statement(statement)

funcname = self._func_named(statement.command)
if not funcname:
self.default(statement)
Expand Down
15 changes: 15 additions & 0 deletions tests/test_cmd2.py
Original file line number Diff line number Diff line change
Expand Up @@ -1787,3 +1787,18 @@ def test_readline_remove_history_item(base_app):
assert readline.get_current_history_length() == 1
readline.remove_history_item(0)
assert readline.get_current_history_length() == 0

def test_onecmd_raw_str_continue(base_app):
line = "help"
stop = base_app.onecmd(line)
out = base_app.stdout.buffer
assert not stop
assert out.strip() == BASE_HELP.strip()

def test_onecmd_raw_str_quit(base_app):
line = "quit"
stop = base_app.onecmd(line)
out = base_app.stdout.buffer
assert stop
assert out == ''