diff --git a/requirements.txt b/requirements.txt index dce6ab6..ee15d09 100644 --- a/requirements.txt +++ b/requirements.txt @@ -9,5 +9,5 @@ WTForms==1.0.5 Werkzeug==0.9.4 itsdangerous==0.24 wsgiref==0.1.2 -docopt==0.6.1 +click==0.7 sphinx-rtd-theme==0.1.6 diff --git a/sandman/sandmanctl.py b/sandman/sandmanctl.py index 1bf7765..cb729ea 100644 --- a/sandman/sandmanctl.py +++ b/sandman/sandmanctl.py @@ -1,73 +1,43 @@ -"""Script to run sandman via command line - -Usage: - sandmanctl.py URI [--show-pks --generate-pks] [--host=host] [--port=port] [--version] - sandmanctl.py --version - -Start sandman and connect to database at URI - -Supported database dialects: - -[PostgreSQL] -[MySQL] -[Oracle] -[Microsoft SQL Server] -[SQLite] -[Drizzle] -[Firebird] -[Sybase] - -External dialects and packages: - -[IBM DB2]: ibm_db_sa -[SAP Sybase SQL Anywhere]: sqlalchemy-sqlany -[MonetDB]: sqlalchemy-monetdb - -Arguments: - URI RFC-1738 style database URI - -Options: - -h --help Show this screen. - -s --show-primary-keys Display primary key columns in the admin - interface - -g --generate-pks Use the combination of all columns as the - primary key for tables without primary keys - (primary keys are required by the mapping - engine). Implies --primary-keys - -v --version Display current version of sandman and exit - --host Host to run sandmanctl on - --port Port to run sandmanctl on - -'postgresql+psycopg2://scott:tiger@localhost/test' -'postgresql+psycopg2://scott:tiger@localhost/test' --generate-pks --host localhost --port 8080 -'sqlite+pysqlite:///relative/path/to/db.db' -'sqlite:////absolute/path/to/db.db' - -""" +"""Script to run sandman via command line.""" from __future__ import absolute_import -import sys -from docopt import docopt +import click from sandman import app from sandman.model import activate -def main(test_options=None): - """Main entry point for script.""" +def print_version(ctx, value): + """Print the current version of sandman and exit.""" + if not value: + return import pkg_resources version = None try: version = pkg_resources.get_distribution('sandman').version finally: del pkg_resources - - options = test_options or docopt(__doc__, version=version) - URI = options['URI'] - app.config['SQLALCHEMY_DATABASE_URI'] = options['URI'] - app.config['SANDMAN_GENERATE_PKS'] = options['--generate-pks'] or False - app.config['SANDMAN_SHOW_PKS'] = options['--show-pks'] or False - host = options.get('--host') or '0.0.0.0' - port = options.get('--port') or 5000 + click.echo(version) + ctx.exit() + + +@click.command() +@click.option('--generate-pks/--no-generate-pks', default=False, + help='Have sandman generate primary keys for tables without one') +@click.option('--show-pks/--no-show-pks', default=False, + help='Have sandman show primary key columns in the admin view') +@click.option('--host', default='0.0.0.0', + help='Hostname of database server to connect to') +@click.option('--port', default=8080, + help='Port of database server to connect to') +@click.option('--version', is_flag=True, + callback=print_version, expose_value=False, is_eager=True) +@click.argument('URI', metavar='') +def run(generate_pks, show_pks, host, port, uri): + """Connect sandman to and start the API server/admin + interface.""" + app.config['SQLALCHEMY_DATABASE_URI'] = uri + app.config['SANDMAN_GENERATE_PKS'] = generate_pks + app.config['SANDMAN_SHOW_PKS'] = show_pks app.config['SERVER_HOST'] = host app.config['SERVER_PORT'] = port activate(name='sandmanctl') diff --git a/setup.py b/setup.py index 8c7b194..f13e56c 100644 --- a/setup.py +++ b/setup.py @@ -46,7 +46,8 @@ def run_tests(self): 'Flask-Admin>=1.0.6', 'Flask-HTTPAuth>=2.2.1', 'docopt>=0.6.1', - 'sphinx-rtd-theme', + 'click', + #'sphinx-rtd-theme', ], cmdclass={'test': PyTest}, author_email='jeff@jeffknupp.com', @@ -54,7 +55,7 @@ def run_tests(self): long_description=long_description, entry_points={ 'console_scripts': [ - 'sandmanctl = sandman.sandmanctl:main', + 'sandmanctl = sandman.sandmanctl:run', ], }, packages=['sandman', 'sandman.model'], diff --git a/tests/data/chinook.sqlite3 b/tests/data/chinook.sqlite3 index 37de5dc..37587f4 100644 Binary files a/tests/data/chinook.sqlite3 and b/tests/data/chinook.sqlite3 differ