From: Mike Bayer Date: Sun, 25 Apr 2010 13:32:53 +0000 (-0400) Subject: working on cmd line X-Git-Tag: rel_0_1_0~113 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=36a897e7bb939086631a3c8467f9740b89641ac2;p=thirdparty%2Fsqlalchemy%2Falembic.git working on cmd line --- diff --git a/alembic/command.py b/alembic/command.py index ab40617d..8fdc9a45 100644 --- a/alembic/command.py +++ b/alembic/command.py @@ -1,9 +1,19 @@ -from alembic.script import Script +from alembic.script import ScriptDirectory +from alembic import options -def main(options, command): - raise NotImplementedError("yeah yeah nothing here yet") +def main(argv=None): + parser = options.get_option_parser() + opts, args = parser.parse_args(argv[1:]) + if len(args) < 1: + parser.error("no command specified") # Will exit + + print opts.config + +def list_templates(options): + """List available templates""" + def init(options): """Initialize a new scripts directory.""" diff --git a/alembic/options.py b/alembic/options.py index afc26c24..1749400b 100644 --- a/alembic/options.py +++ b/alembic/options.py @@ -1,6 +1,36 @@ +from optparse import OptionParser +import ConfigParser +import textwrap def get_option_parser(): - parser = OptionParser("usage: %prog [options] ") + # TODO: + # OK, what's the super option parser library that + # allows plus command-specfic sub-options ? + + # TODO: pull the commands from command.py directly here + parser = OptionParser( + "usage: %prog [options] \n\n" + "Available Commands:\n" + " list-templates\n" + " init\n" + " revision\n" + " upgrade\n" + " revert\n" + " history\n" + " splice\n" + " branches" + ) + parser.add_option("-c", "--config", + type="string", + default="alembic.ini", + help="Alternate config file") + parser.add_option("-t", "--template", + type="string", + help="Setup template for use with 'init'") + parser.add_option("-r", "--rev", + type="string", + help="Revsion identifier for usage with 'revert'" + ) return parser class Options(object): diff --git a/scripts/alembic b/scripts/alembic old mode 100644 new mode 100755 index df453e2e..65d7e02a --- a/scripts/alembic +++ b/scripts/alembic @@ -1,20 +1,8 @@ #!/usr/bin/env python -import alembic +from alembic import command import sys -from optparse import OptionParser - -def main(argv=None): - parser = alembic.options.get_option_parser() - - opts, args = parser.parse_args(argv[1:]) - if len(args) < 1: - parser.error("no command specified") # Will exit - - command = args[0] - - alembic.main(options, file_config, command) if __name__ == "__main__": - main(sys.argv) + command.main(sys.argv)