Skip to content
Snippets Groups Projects
Commit 334d1483 authored by Iustin Pop's avatar Iustin Pop
Browse files

Extend GenericMain with a way to override options

This allows scripts to pass options to generic functions (options that
are not visible in the command line).

Reviewed-by: imsnah
parent 1977857b
No related branches found
No related tags found
Loading
...@@ -240,11 +240,15 @@ def SubmitOpCode(op): ...@@ -240,11 +240,15 @@ def SubmitOpCode(op):
return proc.ExecOpCode(op, logger.ToStdout) return proc.ExecOpCode(op, logger.ToStdout)
def GenericMain(commands): def GenericMain(commands, override=None):
"""Generic main function for all the gnt-* commands. """Generic main function for all the gnt-* commands.
Argument: a dictionary with a special structure, see the design doc Arguments:
for command line handling. - commands: a dictionary with a special structure, see the design doc
for command line handling.
- override: if not None, we expect a dictionary with keys that will
override command line options; this can be used to pass
options from the scripts to generic functions
""" """
# save the program name and the entire command line for later logging # save the program name and the entire command line for later logging
...@@ -263,6 +267,10 @@ def GenericMain(commands): ...@@ -263,6 +267,10 @@ def GenericMain(commands):
if func is None: # parse error if func is None: # parse error
return 1 return 1
if override is not None:
for key, val in override.iteritems():
setattr(options, key, val)
logger.SetupLogging(debug=options.debug, program=binary) logger.SetupLogging(debug=options.debug, program=binary)
try: try:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment