summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZuul <zuul@review.openstack.org>2018-06-20 15:41:28 +0000
committerGerrit Code Review <review@openstack.org>2018-06-20 15:41:28 +0000
commit92672471a2031a33c2b42218393d3305cdb2239a (patch)
treefbffbcb2b65af1a2d76d1228a826f65837cebb94
parent838fc650a99ba29e303b1b5debd51bb74cf636d6 (diff)
parenta9dd3a912a4cd287982c42ca328ecfe3d18abadf (diff)
downloadcliff-92672471a2031a33c2b42218393d3305cdb2239a.tar.gz
Merge "support cmd2 0.9.1 in interactive mode"2.12.1
-rw-r--r--cliff/interactive.py32
1 files changed, 27 insertions, 5 deletions
diff --git a/cliff/interactive.py b/cliff/interactive.py
index 2d17523..f5afa1b 100644
--- a/cliff/interactive.py
+++ b/cliff/interactive.py
@@ -51,13 +51,24 @@ class InteractiveApp(cmd2.Cmd):
self.command_manager = command_manager
cmd2.Cmd.__init__(self, 'tab', stdin=stdin, stdout=stdout)
+ def _split_line(self, line):
+ try:
+ return shlex.split(line.parsed.raw)
+ except AttributeError:
+ # cmd2 >= 0.9.1 gives us a Statement not a PyParsing parse
+ # result.
+ parts = shlex.split(line)
+ if getattr(line, 'command', None):
+ parts.insert(0, line.command)
+ return parts
+
def default(self, line):
# Tie in the default command processor to
# dispatch commands known to the command manager.
# We send the message through our parent app,
# since it already has the logic for executing
# the subcommand.
- line_parts = shlex.split(line.parsed.raw)
+ line_parts = self._split_line(line)
self.parent_app.run_subcommand(line_parts)
def completenames(self, text, line, begidx, endidx):
@@ -116,7 +127,11 @@ class InteractiveApp(cmd2.Cmd):
# requirements.txt has cmd2 >= 0.7.3.
parsed = self.parsed
except AttributeError:
- parsed = self.parser_manager.parsed
+ try:
+ parsed = self.parser_manager.parsed
+ except AttributeError:
+ # cmd2 >= 0.9.1 does not have a parser manager
+ parsed = lambda x: x # noqa
self.default(parsed('help ' + arg))
else:
cmd2.Cmd.do_help(self, arg)
@@ -140,7 +155,7 @@ class InteractiveApp(cmd2.Cmd):
# Pre-process the parsed command in case it looks like one of
# our subcommands, since cmd2 does not handle multi-part
# command names by default.
- line_parts = shlex.split(statement.parsed.raw)
+ line_parts = self._split_line(statement)
try:
the_cmd = self.command_manager.find_command(line_parts)
cmd_factory, cmd_name, sub_argv = the_cmd
@@ -148,8 +163,15 @@ class InteractiveApp(cmd2.Cmd):
# Not a plugin command
pass
else:
- statement.parsed.command = cmd_name
- statement.parsed.args = ' '.join(sub_argv)
+ if hasattr(statement, 'parsed'):
+ # Older cmd2 uses PyParsing
+ statement.parsed.command = cmd_name
+ statement.parsed.args = ' '.join(sub_argv)
+ else:
+ # cmd2 >= 0.9.1 uses shlex and gives us a Statement.
+ statement.command = cmd_name
+ statement.argv = [cmd_name] + sub_argv
+ statement.args = ' '.join(statement.argv)
return statement
def cmdloop(self):