Commit 77e7bef7 authored by Stavros Sachtouris's avatar Stavros Sachtouris

Complete top-level commands from everywhere

Usage: in kamaki shell, from any context, user can write:

/<command> <subcmds... and params...>
parent 524dc2f8
......@@ -70,16 +70,23 @@ class Shell(Cmd):
undoc_header = 'interactive shell commands:'
def postcmd(self, post, line):
if self._context_stack:
self._roll_command()
self.set_prompt(self._prompt_stack.pop()[1:-2])
self._restore(self._context_stack.pop())
return Cmd.postcmd(self, post, line)
def precmd(self, line):
if line.startswith('/'):
cur_cmd_path = self.prompt.replace(' ', '_')[1:-2]
if cur_cmd_path != self.cmd_tree.name:
cur_cmd = self.cmd_tree.get_command(cur_cmd_path)
self._context_stack.append(self._backup())
self._prompt_stack.append(self.prompt)
new_context = self
new_context._roll_command(cur_cmd_path)
new_context._roll_command(cur_cmd.parent_path)
new_context.set_prompt(self.cmd_tree.name)
for grp_cmd in self.cmd_tree.get_subcommands():
self._register_command(grp_cmd.path)
......@@ -118,7 +125,7 @@ class Shell(Cmd):
except KeyError:
pass
def _roll_command(self, cmd_path):
def _roll_command(self, cmd_path=None):
for subname in self.cmd_tree.get_subnames(cmd_path):
self._unregister_method('do_%s' % subname)
self._unregister_method('complete_%s' % subname)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment