summaryrefslogtreecommitdiffstats
path: root/scripts/automation/trex_control_plane/stl/trex_stl_lib/utils/parsing_opts.py
diff options
context:
space:
mode:
authorimarom <imarom@cisco.com>2017-01-26 17:26:00 +0200
committerimarom <imarom@cisco.com>2017-01-26 17:34:28 +0200
commitacf815dbf67d7a3be8fefd84eea1d25465f71136 (patch)
tree6d6b68dd250cdc910c6aa51858532b1844dae868 /scripts/automation/trex_control_plane/stl/trex_stl_lib/utils/parsing_opts.py
parent3689edf311778c8cb921db61f293db6cd43a9b14 (diff)
code review - few cleanups
Signed-off-by: imarom <imarom@cisco.com>
Diffstat (limited to 'scripts/automation/trex_control_plane/stl/trex_stl_lib/utils/parsing_opts.py')
-rwxr-xr-xscripts/automation/trex_control_plane/stl/trex_stl_lib/utils/parsing_opts.py11
1 files changed, 10 insertions, 1 deletions
diff --git a/scripts/automation/trex_control_plane/stl/trex_stl_lib/utils/parsing_opts.py b/scripts/automation/trex_control_plane/stl/trex_stl_lib/utils/parsing_opts.py
index 8d3aedbe..53db533c 100755
--- a/scripts/automation/trex_control_plane/stl/trex_stl_lib/utils/parsing_opts.py
+++ b/scripts/automation/trex_control_plane/stl/trex_stl_lib/utils/parsing_opts.py
@@ -689,19 +689,23 @@ class _MergeAction(argparse._AppendAction):
class CCmdArgParser(argparse.ArgumentParser):
- def __init__(self, stateless_client = None, x = None, *args, **kwargs):
+ def __init__(self, stateless_client = None, *args, **kwargs):
super(CCmdArgParser, self).__init__(*args, **kwargs)
self.stateless_client = stateless_client
self.cmd_name = kwargs.get('prog')
self.register('action', 'merge', _MergeAction)
+
def add_arg_list (self, *args):
populate_parser(self, *args)
+
+ # a simple hook for add subparsers to add stateless client
def add_subparsers(self, *args, **kwargs):
sub = super(CCmdArgParser, self).add_subparsers(*args, **kwargs)
+ # save pointer to the original add parser method
add_parser = sub.add_parser
stateless_client = self.stateless_client
@@ -710,13 +714,17 @@ class CCmdArgParser(argparse.ArgumentParser):
parser.stateless_client = stateless_client
return parser
+ # override with the hook
sub.add_parser = add_parser_hook
+
return sub
+
# hook this to the logger
def _print_message(self, message, file=None):
self.stateless_client.logger.log(message)
+
def error(self, message):
self.print_usage()
self._print_message(('%s: error: %s\n') % (self.prog, message))
@@ -783,6 +791,7 @@ class CCmdArgParser(argparse.ArgumentParser):
# recover from system exit scenarios, such as "help", or bad arguments.
return RC_ERR("'{0}' - {1}".format(self.cmd_name, "no action"))
+
def formatted_error (self, msg):
self.print_usage()
self._print_message(('%s: error: %s\n') % (self.prog, msg))