summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDoug Hellmann <doug.hellmann@dreamhost.com>2012-05-14 17:32:54 -0400
committerDoug Hellmann <doug.hellmann@dreamhost.com>2012-05-14 17:32:54 -0400
commit4bc39f72e8e9a6772f3d2eb9295809658c1793d7 (patch)
tree5e4ff1e6de206f6c39e749cb779caa4a86adc58b
parent0be17dec6b12909517c9079ff4a3c5a56d640704 (diff)
downloadcliff-tablib-4bc39f72e8e9a6772f3d2eb9295809658c1793d7.tar.gz
fix interactive command processor to handle multi-part commands, including some that use the same first word as existing commands
-rw-r--r--cliff/interactive.py17
1 files changed, 16 insertions, 1 deletions
diff --git a/cliff/interactive.py b/cliff/interactive.py
index 2543b20..35fcc47 100644
--- a/cliff/interactive.py
+++ b/cliff/interactive.py
@@ -43,7 +43,7 @@ class InteractiveApp(cmd2.Cmd):
# We send the message through our parent app,
# since it already has the logic for executing
# the subcommand.
- line_parts = shlex.split(line)
+ line_parts = shlex.split(line.parsed.raw)
self.parent_app.run_subcommand(line_parts)
def completedefault(self, text, line, begidx, endidx):
@@ -95,3 +95,18 @@ class InteractiveApp(cmd2.Cmd):
for n in cmd2.Cmd.get_names(self)
if not n.startswith('do__')
]
+
+ def precmd(self, statement):
+ # 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)
+ try:
+ cmd_factory, cmd_name, sub_argv = self.command_manager.find_command(line_parts)
+ except ValueError:
+ # Not a plugin command
+ pass
+ else:
+ statement.parsed.command = cmd_name
+ statement.parsed.args = ' '.join(sub_argv)
+ return statement