From 4bc39f72e8e9a6772f3d2eb9295809658c1793d7 Mon Sep 17 00:00:00 2001 From: Doug Hellmann Date: Mon, 14 May 2012 17:32:54 -0400 Subject: fix interactive command processor to handle multi-part commands, including some that use the same first word as existing commands --- cliff/interactive.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) 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 -- cgit v1.2.1