From 334d14837fc51e6dd7fe83533367cce78abd9a04 Mon Sep 17 00:00:00 2001
From: Iustin Pop <iustin@google.com>
Date: Mon, 8 Oct 2007 14:42:03 +0000
Subject: [PATCH] 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
---
 lib/cli.py | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/lib/cli.py b/lib/cli.py
index fbc7f12ea..e9bec2aed 100644
--- a/lib/cli.py
+++ b/lib/cli.py
@@ -240,11 +240,15 @@ def SubmitOpCode(op):
   return proc.ExecOpCode(op, logger.ToStdout)
 
 
-def GenericMain(commands):
+def GenericMain(commands, override=None):
   """Generic main function for all the gnt-* commands.
 
-  Argument: a dictionary with a special structure, see the design doc
-  for command line handling.
+  Arguments:
+    - 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
@@ -263,6 +267,10 @@ def GenericMain(commands):
   if func is None: # parse error
     return 1
 
+  if override is not None:
+    for key, val in override.iteritems():
+      setattr(options, key, val)
+
   logger.SetupLogging(debug=options.debug, program=binary)
 
   try:
-- 
GitLab