Last active
September 22, 2015 14:33
-
-
Save larsimmisch/51f57fcbad56e3941384 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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