]> scripts.mit.edu Git - wizard.git/commitdiff
Implement required/optional argument grouping.
authorEdward Z. Yang <ezyang@mit.edu>
Mon, 2 Nov 2009 21:03:26 +0000 (16:03 -0500)
committerEdward Z. Yang <ezyang@mit.edu>
Mon, 2 Nov 2009 21:03:26 +0000 (16:03 -0500)
Signed-off-by: Edward Z. Yang <ezyang@mit.edu>
wizard/command/install.py
wizard/install/installopt.py
wizard/install/interactive.py

index 49d067ac2027446dd4c4daa74f706a486cec6fe9..cacaf3ca8d413bde3029f3a9c05cbe1b125c58f0 100644 (file)
@@ -22,12 +22,14 @@ def main(argv, baton):
 
     # get configuration
     schema = application.install_schema
+    schema.commit(dir)
     options = None
     opthandler = installopt.Controller(dir, schema)
     ihandler = interactive.Controller(dir, schema, input)
     parser = command.WizardOptionParser("""usage: %%prog install %s DIR [ -- SETUPARGS ]
 
 Autoinstalls the application %s in the directory DIR.""" % (appname, appname))
+    configure_parser(parser, baton)
     opthandler.push(parser)
     if old_options.help:
         parser.print_help()
@@ -50,18 +52,26 @@ Autoinstalls the application %s in the directory DIR.""" % (appname, appname))
         git.commit_configure()
     input.infobox("Congratulations, your new install is now accessible at http://%s%s" % (options.web_host, options.web_path))
 
+def configure_parser(parser, baton):
+    parser.add_option("--prompt", dest="prompt", action="store_true",
+            default=False, help="Force to use non-ncurses interactive interface")
+    parser.add_option("--non-interactive", dest="non_interactive", action="store_true",
+            default=False, help="Force program to be non-interactive and use SETUPARGS.  Use --help with APP to find argument names.")
+    baton.push(parser, "srv_path")
+
 def parse_args(argv, baton):
     usage = """usage: %prog install APP DIR [ -- SETUPARGS ]
 
 Autoinstalls the application APP in the directory DIR.
 This command will interactively ask for information to
-complete the autoinstall."""
+complete the autoinstall.
+
+You can also use --help with APP and DIR to find out what
+are required SETUPARGS if you want to run this non-interactively
+(the distribution of required and optional arguments may change
+depending on what directory you are installing to.)"""
     parser = command.WizardOptionParser(usage, store_help=True)
-    parser.add_option("--prompt", dest="prompt", action="store_true",
-            default=False, help="Force to use non-ncurses interactive interface")
-    parser.add_option("--non-interactive", dest="non_interactive", action="store_true",
-            default=False, help="Force program to be non-interactive and use SETUPARGS.  Use --help with APP to find argument names.")
-    baton.push(parser, "srv_path")
+    configure_parser(parser, baton)
     options, args = parser.parse_all(argv)
     if options.help:
         if len(args) == 0:
index 06437f29a82a0d9adcc7c03acde1f694ad3f9f88..e6c031475ae43975a551c0daa9ec1236935f318d 100644 (file)
@@ -1,3 +1,5 @@
+import optparse
+
 def attr_to_option(variable):
     """
     Converts Python attribute names to command line options.
@@ -16,13 +18,17 @@ class Controller(object):
         self.schema = schema
     def push(self, parser):
         """Pushes arg schema to :class:`optparse.OptionParser`."""
+        required = optparse.OptionGroup(parser, "Required Arguments (SETUPARGS)")
+        optional = optparse.OptionGroup(parser, "Optional Arguments (SETUPARGS)")
         for arg in self.schema.args.values():
-            parser.add_option(attr_to_option(arg.name), dest=arg.name, metavar=arg.type,
+            group = arg.name in self.schema.provides and optional or required
+            group.add_option(attr_to_option(arg.name), dest=arg.name, metavar=arg.type,
                     default=None, help=arg.help)
+        parser.add_option_group(required)
+        parser.add_option_group(optional)
     def handle(self, options):
         """
         Performs post-processing for the options, including throwing
         errors if not all arguments are specified.
         """
-        self.schema.commit(self.dir)
         self.schema.load(options)
index d830206d00f400a0191d685246d66eb452193873..37ce807aa5611df8d22758cb0f6a20e770b3ade4 100644 (file)
@@ -13,7 +13,6 @@ class Controller(object):
         """
         Interactively ask the user for information.
         """
-        self.schema.commit(self.dir)
         self.schema.fill(options)
         for name, arg in self.schema.args.items():
             if name in self.schema.provides: