Skip to content

Commit 6c90d3c

Browse files
committed
Allow onecmd to accept a raw string for backward compatibility with cmd
This addresses #464
1 parent 6ddb684 commit 6c90d3c

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

cmd2/cmd2.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1901,14 +1901,19 @@ def _func_named(self, arg: str) -> str:
19011901
result = target
19021902
return result
19031903

1904-
def onecmd(self, statement: Statement) -> Optional[bool]:
1904+
def onecmd(self, statement: Union[Statement, str]) -> Optional[bool]:
19051905
""" This executes the actual do_* method for a command.
19061906
19071907
If the command provided doesn't exist, then it executes _default() instead.
19081908
1909-
:param statement: Command - a parsed command from the input stream
1909+
:param statement: Command - intended to be a Statement instance parsed command from the input stream,
1910+
alternative acceptance of a str is present only for backward compatibility with cmd
19101911
:return: a flag indicating whether the interpretation of commands should stop
19111912
"""
1913+
# For backwards compatibility with cmd, allow a str to be passed in
1914+
if not isinstance(statement, Statement):
1915+
statement = self._complete_statement(statement)
1916+
19121917
funcname = self._func_named(statement.command)
19131918
if not funcname:
19141919
self.default(statement)

0 commit comments

Comments
 (0)