Parcourir la source

[trac615] Take parsing of args to a function

The parsing is taken out so it can be tested independently on the rest.
We don't need to run the main function now.
Michal 'vorner' Vaner il y a 14 ans
Parent
commit
79155a51eb
1 fichiers modifiés avec 15 ajouts et 7 suppressions
  1. 15 7
      src/bin/bind10/bind10.py.in

+ 15 - 7
src/bin/bind10/bind10.py.in

@@ -785,13 +785,11 @@ def process_rename(option, opt_str, value, parser):
     """Function that renames the process if it is requested by a option."""
     isc.util.process.rename(value)
 
-def main():
-    global options
-    global boss_of_bind
-    # Enforce line buffering on stdout, even when not a TTY
-    sys.stdout = io.TextIOWrapper(sys.stdout.detach(), line_buffering=True)
-
-    # Parse any command-line options.
+def parse_args(args=sys.argv[1:]):
+    """
+    Function for parsing command line arguments. Returns the
+    options object from OptionParser.
+    """
     parser = OptionParser(version=VERSION)
     parser.add_option("-m", "--msgq-socket-file", dest="msgq_socket_file",
                       type="string", default=None,
@@ -810,6 +808,16 @@ def main():
         parser.print_help()
         sys.exit(1)
 
+    return options
+
+def main():
+    global options
+    global boss_of_bind
+    # Enforce line buffering on stdout, even when not a TTY
+    sys.stdout = io.TextIOWrapper(sys.stdout.detach(), line_buffering=True)
+
+    options = parse_args()
+
     # Check user ID.
     setuid = None
     username = None