Skip to content

Instantly share code, notes, and snippets.

@larsimmisch
Last active September 22, 2015 14:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save larsimmisch/51f57fcbad56e3941384 to your computer and use it in GitHub Desktop.
Save larsimmisch/51f57fcbad56e3941384 to your computer and use it in GitHub Desktop.
import os
import click
def prompt_and_invoke(ctx, fn):
# This is a workaround for a bug in click.
# See https://github.com/mitsuhiko/click/issues/429
# This isn't perfect - we are probably ignoring some information
kw = {}
for p in fn.params:
v = click.prompt(p.prompt, p.default, p.hide_input,
p.confirmation_prompt, p.type)
kw[p.name.upper()] = v
ctx.invoke(fn, **kw)
@click.command()
@click.option('--site-title',
default="Notizen",
prompt='Enter site title.')
@click.option('--user-backend',
default="db",
type=click.Choice(['db', 'ldap']),
prompt='User backend?')
@click.pass_context
def setup(ctx, **kw):
""" Start setup wizard
"""
if kw.get('user_backend', None) == 'db':
prompt_and_invoke(ctx, setup_db)
@click.command()
@click.option('--db_url',
default='sqlite://///tmp/notizen.sql',
prompt='Database URL?')
@click.pass_context
def setup_db(ctx, **kw):
pass
if __name__ == '__main__':
setup()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment