Commit f2e2663e authored by Stavros Sachtouris's avatar Stavros Sachtouris
Browse files

Rename history.recall to load, allow multiple ids

load 1 3 5-7 8 ...
also can repeat commands:
load 1 4 1 3-5 (repeats 1 and 4)
parent fce93ff6
......@@ -165,7 +165,7 @@ class Shell(Cmd):
# exec command or change context
if subcmd.is_command: # exec command
cls = subcmd.get_class()
if subcmd.path == 'history_recall':
if subcmd.path == 'history_load':
instance = cls(dict(cmd_parser.arguments), self.cmd_tree)
else:
instance = cls(dict(cmd_parser.arguments))
......
......@@ -40,7 +40,7 @@ from kamaki.cli.history import History
from kamaki.cli import command
from kamaki.cli.commands import _command_init
from kamaki.cli import _exec_cmd, _print_error_message
from kamaki.cli.errors import CLIError
from kamaki.cli.errors import CLIError, raiseCLIError
from kamaki.cli.utils import split_input
from kamaki.clients import ClientError
......@@ -82,7 +82,7 @@ class history_clean(_init_history):
@command(history_cmds)
class history_recall(_init_history):
class history_load(_init_history):
"""Re-call a previously called command"""
_cmd_tree = None
......@@ -111,10 +111,26 @@ class history_recall(_init_history):
print('Execution of [ %s ] failed' % line)
print('\t%s' % e)
def main(self, commandid):
def _get_cmd_ids(self, cmd_ids):
cmd_id_list = []
for cmd_str in cmd_ids:
num1, sep, num2 = cmd_str.partition('-')
try:
if sep:
for i in range(int(num1), int(num2) + 1):
cmd_id_list.append(i)
else:
cmd_id_list.append(int(cmd_str))
except ValueError:
raiseCLIError('Invalid history id %s' % cmd_str)
return cmd_id_list
def main(self, *command_ids):
super(self.__class__, self).main()
r = self.history.retrieve(commandid)
print(r[:-1])
if self._cmd_tree:
r = r[len('kamaki '):-1] if r.startswith('kamaki ') else r[:-1]
self._run_from_line(r)
cmd_list = self._get_cmd_ids(command_ids)
for cmd_id in cmd_list:
r = self.history.retrieve(cmd_id)
print(r[:-1])
if self._cmd_tree:
r = r[len('kamaki '):-1] if r.startswith('kamaki ') else r[:-1]
self._run_from_line(r)
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