Revision 53254b46 kamaki/cli/command_shell.py
b/kamaki/cli/command_shell.py | ||
---|---|---|
63 | 63 |
class Shell(Cmd): |
64 | 64 |
"""Kamaki interactive shell""" |
65 | 65 |
_prefix = '[' |
66 |
_suffix = ']:' |
|
66 |
_suffix = ']: '
|
|
67 | 67 |
cmd_tree = None |
68 | 68 |
_history = None |
69 | 69 |
_context_stack = [] |
... | ... | |
76 | 76 |
if self._context_stack: |
77 | 77 |
self._roll_command() |
78 | 78 |
self._restore(self._context_stack.pop()) |
79 |
self.set_prompt(self._prompt_stack.pop()[1:-2]) |
|
79 |
self.set_prompt( |
|
80 |
self._prompt_stack.pop()[len(self._prefix):-len(self._suffix)]) |
|
80 | 81 |
|
81 | 82 |
return Cmd.postcmd(self, post, line) |
82 | 83 |
|
83 | 84 |
def precmd(self, line): |
84 | 85 |
if line.startswith('/'): |
85 |
cur_cmd_path = self.prompt.replace(' ', '_')[1:-2] |
|
86 |
cur_cmd_path = self.prompt.replace(' ', |
|
87 |
'_')[len(self._prefix):-len(self._suffix)] |
|
86 | 88 |
if cur_cmd_path != self.cmd_tree.name: |
87 | 89 |
cur_cmd = self.cmd_tree.get_command(cur_cmd_path) |
88 | 90 |
self._context_stack.append(self._backup()) |
... | ... | |
100 | 102 |
% version) |
101 | 103 |
|
102 | 104 |
def set_prompt(self, new_prompt): |
103 |
self.prompt = '[%s]:' % new_prompt
|
|
105 |
self.prompt = '%s%s%s' % (self._prefix, new_prompt, self._suffix)
|
|
104 | 106 |
|
105 | 107 |
def do_exit(self, line): |
106 | 108 |
print('') |
107 |
if self.prompt[1:-2] == self.cmd_tree.name: |
|
109 |
if self.prompt[len(self._prefix):-len(self._suffix)]\ |
|
110 |
== self.cmd_tree.name: |
|
108 | 111 |
exit(0) |
109 | 112 |
return True |
110 | 113 |
|
Also available in: Unified diff