From 0e6de767e836cd04bcfb0690f5138233c84b96b4 Mon Sep 17 00:00:00 2001 From: "Edward Z. Yang" Date: Tue, 11 Aug 2009 22:34:57 -0400 Subject: [PATCH] Implement less braindead help messages for installation. Signed-off-by: Edward Z. Yang --- API | 28 ++++++++++++++++++++++++++++ wizard/command/configure.py | 30 ++++++++++++++++++++++++------ wizard/command/install.py | 9 +++++++-- wizard/install.py | 23 +++++++++++++---------- 4 files changed, 72 insertions(+), 18 deletions(-) create mode 100644 API diff --git a/API b/API new file mode 100644 index 0000000..26971f5 --- /dev/null +++ b/API @@ -0,0 +1,28 @@ +wizard install + Loads interactive autoinstaller. Users generally should use this. +wizard install --help + Help message, very basic, indicates: + - How to run the interactive installer + - How to specify an installation directory + - How to specify a specific application + - How to specify a specific version + - How to get help for that application +wizard install mediawiki + Installs MediaWiki application. Interactively asks for install + location and configuration. +wizard install mediawiki --help + Help message for that application. Show the configure message. + This is tricky, since just bouncing back wizard configure --help + will result in the wrong program name. Choices: + X Tell the user the appropriate command to get the correct help + choice. Poor because it makes them jump through an extra hoop, + however, once they have it makes "more sense" + This is the approach we'll take for now, before we make + ArgHandler work. + * Manually search replace the output of the configure command. + Hacky. + * Rewrite optparse to have a more robust %app substitution, + which includes being able to override it. Ehh... + X Manual help generation out of ArgHandler. Not bad, but requires + code to be written. + This is the correct solution, and should eventually be implemented. diff --git a/wizard/command/configure.py b/wizard/command/configure.py index fa2a8b9..bdd3210 100644 --- a/wizard/command/configure.py +++ b/wizard/command/configure.py @@ -1,20 +1,38 @@ import logging +import optparse import sys from wizard import command, deploy, git def main(argv, baton): - # SKETCHY! - tag = git.describe() - application, _, version = tag.partition('-') - app = deploy.applications()[application] - handler = app.install_handler usage = """usage: %prog configure [ARGS] Takes an already cloned working copy and configures the application. Options change depending on the current -working directory.""" +working directory. + +WARNING: This command's API may change.""" + + # XXX: squick squick squick + if argv and argv[0][0] != '-': + if '--help' not in argv and '-h' not in argv: + argv.append('--help') + if '--help' in argv or '-h' in argv: + # Do a "fake parse" in order to get out the application name + parser = optparse.OptionParser(usage, add_help_option=False) + parser.add_option("--help", "-h", action="store_true") + options, args = parser.parse_args(argv) + try: + application = args[0] + except IndexError: + parser.error("Use 'wizard configure --help APP' to see APP-specific options.") + else: + tag = git.describe() + application, _, version = tag.partition('-') + + app = deploy.applications()[application] + handler = app.install_handler parser = command.WizardOptionParser(usage) handler.push(parser) diff --git a/wizard/command/install.py b/wizard/command/install.py index faf627b..a331e2e 100644 --- a/wizard/command/install.py +++ b/wizard/command/install.py @@ -27,9 +27,14 @@ def main(argv, baton): sys.exit(1) def parse_args(argv): - usage = """usage: %prog install [--app APP] [DIR -- [SETUPARGS]] + usage = """usage: %prog install [APP [DIR -- [SETUPARGS]]] -Autoinstalls an application.""" +Autoinstalls the application APP in the directory +DIR. SETUPARGS are arguments that are passed to +'wizard configure', see 'wizard configure APP --help' +for possible arguments. + +WARNING: This command's API may change.""" parser = command.WizardOptionParser(usage) parser.add_option("--app", dest="app", help="Application to install, optionally specifying a version as APP-VERSION") diff --git a/wizard/install.py b/wizard/install.py index f019216..7c99957 100644 --- a/wizard/install.py +++ b/wizard/install.py @@ -162,14 +162,17 @@ class Arg(object): name = None #: Help string help = None + #: String "type" of the argument, used for metavar + type = None @property def option(self): """Full string of the option.""" return attr_to_option(self.name) - def __init__(self, name, password=False, help="XXX: UNDOCUMENTED"): + def __init__(self, name, password=False, type=None, help="XXX: UNDOCUMENTED"): self.name = name self.password = password self.help = help + self.type = type class ArgSet(object): """ @@ -190,8 +193,8 @@ class WebArgSet(ArgSet): """Common arguments for any application that lives on the web.""" def __init__(self): self.args = [ - Arg("web_host", help="Host that the application will live on"), - Arg("web_path", help="Relative path to your application root"), + Arg("web_host", type="HOST", help="Host that the application will live on"), + Arg("web_path", type="PATH", help="Relative path to your application root"), ] self.strategy = ScriptsWebStrategy() @@ -199,10 +202,10 @@ class MysqlArgSet(ArgSet): """Common arguments for applications that use a MySQL database.""" def __init__(self): self.args = [ - Arg("mysql_host", help="Host that your MySQL server lives on"), - Arg("mysql_db", help="Name of the database to populate"), - Arg("mysql_user", help="Name of user to access database with"), - Arg("mysql_password", password=True, help="Password of the database user"), + Arg("mysql_host", type="HOST", help="Host that your MySQL server lives on"), + Arg("mysql_db", type="DB", help="Name of the database to populate"), + Arg("mysql_user", type="USER", help="Name of user to access database with"), + Arg("mysql_password", type="PWD", password=True, help="Password of the database user"), ] self.strategy = ScriptsMysqlStrategy() @@ -210,8 +213,8 @@ class AdminArgSet(ArgSet): """Common arguments when an admin account is to be created.""" def __init__(self): self.args = [ - Arg("admin_name", help="Name of admin user to create"), - Arg("admin_password", password=True, help="Password of admin user"), + Arg("admin_name", type="NAME", help="Name of admin user to create"), + Arg("admin_password", type="PWD", password=True, help="Password of admin user"), ] class EmailArgSet(ArgSet): @@ -266,7 +269,7 @@ class ArgHandler(object): """Pushes arg schema to :class:`optparse.OptionParser`.""" for argset in self.argsets: for arg in argset.args: - parser.add_option(attr_to_option(arg.name), dest=arg.name, + parser.add_option(attr_to_option(arg.name), dest=arg.name, metavar=arg.type, default=None, help=arg.help) def handle(self, options): """ -- 2.45.2