summaryrefslogtreecommitdiff
path: root/cmd2/cmd2.py
diff options
context:
space:
mode:
authorTodd Leonhardt <todd.leonhardt@gmail.com>2018-07-11 09:32:02 -0400
committerGitHub <noreply@github.com>2018-07-11 09:32:02 -0400
commite10afbeb6efe7dd806b04bd53eca615bca5d5ffc (patch)
tree29c11f4ce7032f06f5ee54452c42b24799870eaf /cmd2/cmd2.py
parent6ddb6842e5ac87fb5c433eb8d86df48f3e045da2 (diff)
parent4f90260edb21d6134338e43f5465b54b261db2c5 (diff)
downloadcmd2-git-e10afbeb6efe7dd806b04bd53eca615bca5d5ffc.tar.gz
Merge pull request #465 from python-cmd2/onecmd_str
Allow onecmd to accept a raw string for backward compatibility with cmd
Diffstat (limited to 'cmd2/cmd2.py')
-rw-r--r--cmd2/cmd2.py9
1 files changed, 7 insertions, 2 deletions
diff --git a/cmd2/cmd2.py b/cmd2/cmd2.py
index 42e00c39..44f3a068 100644
--- a/cmd2/cmd2.py
+++ b/cmd2/cmd2.py
@@ -1901,14 +1901,19 @@ class Cmd(cmd.Cmd):
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)