summaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
authorimarom <imarom@cisco.com>2015-11-25 03:51:37 -0500
committerimarom <imarom@cisco.com>2015-11-25 03:51:37 -0500
commit963da09589fe8376f2750e4d0dc741d48eea6132 (patch)
treef3302e8aaac09e904b1554b4ea2c19e21e83cb29 /scripts
parente5e2692e6dc32dae7b55f3e1435081b5ca732220 (diff)
added history command support - you can show the history or execute a previous command
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/automation/trex_control_plane/console/parsing_opts.py5
-rwxr-xr-xscripts/automation/trex_control_plane/console/trex_console.py57
2 files changed, 60 insertions, 2 deletions
diff --git a/scripts/automation/trex_control_plane/console/parsing_opts.py b/scripts/automation/trex_control_plane/console/parsing_opts.py
index ab678586..14e8c563 100755
--- a/scripts/automation/trex_control_plane/console/parsing_opts.py
+++ b/scripts/automation/trex_control_plane/console/parsing_opts.py
@@ -23,6 +23,11 @@ FORCE = 10
# list of ArgumentGroup types
MUTEX = 1
+def check_negative(value):
+ ivalue = int(value)
+ if ivalue < 0:
+ raise argparse.ArgumentTypeError("non positive value provided: '{0}'".format(value))
+ return ivalue
def match_time_unit(val):
'''match some val against time shortcut inputs '''
diff --git a/scripts/automation/trex_control_plane/console/trex_console.py b/scripts/automation/trex_control_plane/console/trex_console.py
index 2a6fd2eb..0dabe2c3 100755
--- a/scripts/automation/trex_control_plane/console/trex_console.py
+++ b/scripts/automation/trex_control_plane/console/trex_console.py
@@ -70,6 +70,23 @@ class TRexGeneralCmd(cmd.Cmd):
readline.write_history_file(self._history_file)
return
+ def print_history (self):
+
+ length = readline.get_current_history_length()
+
+ for i in xrange(1, length + 1):
+ cmd = readline.get_history_item(i)
+ print "{:<5} {:}".format(i, cmd)
+
+ def get_history_item (self, index):
+ length = readline.get_current_history_length()
+ if index > length:
+ print format_text("please select an index between {0} and {1}".format(0, length))
+ return None
+
+ return readline.get_history_item(index)
+
+
def emptyline(self):
"""Called when an empty line is entered in response to the prompt.
@@ -217,6 +234,41 @@ class TRexConsole(TRexGeneralCmd):
else:
print format_text("\nplease specify 'on' or 'off'\n", 'bold')
+ # show history
+ def help_history (self):
+ self.do_history("-h")
+
+ def do_history (self, line):
+ '''Manage the command history\n'''
+
+ item = parsing_opts.ArgumentPack(['item'],
+ {"nargs": '?',
+ 'metavar': 'item',
+ 'type': parsing_opts.check_negative,
+ 'help': "an history item index",
+ 'default': 0})
+
+ parser = parsing_opts.gen_parser(self,
+ "history",
+ self.do_history.__doc__,
+ item)
+
+ opts = parser.parse_args(line.split())
+ if opts is None:
+ return
+
+ if opts.item == 0:
+ self.print_history()
+ else:
+ cmd = self.get_history_item(opts.item)
+ print cmd
+ if cmd == None:
+ return
+
+ print cmd
+ self.onecmd(cmd)
+
+
############### connect
def do_connect (self, line):
@@ -324,7 +376,7 @@ class TRexConsole(TRexGeneralCmd):
cmds = [x[3:] for x in self.get_names() if x.startswith("do_")]
for cmd in cmds:
- if ( (cmd == "EOF") or (cmd == "q") or (cmd == "exit")):
+ if ( (cmd == "EOF") or (cmd == "q") or (cmd == "exit") or (cmd == "h")):
continue
try:
@@ -338,8 +390,9 @@ class TRexConsole(TRexGeneralCmd):
print "{:<30} {:<30}".format(cmd + " - ", help)
+ # aliases
do_exit = do_EOF = do_q = do_quit
-
+ do_h = do_history
#
def is_valid_file(filename):