Skip to content

Instantly share code, notes, and snippets.

@lidi
Last active August 29, 2015 14:01
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 lidi/d8d9dee41f9029bb5140 to your computer and use it in GitHub Desktop.
Save lidi/d8d9dee41f9029bb5140 to your computer and use it in GitHub Desktop.
prompt_test = True
@click.group()
@click.option('--mode', is_flag=True)
def cli(mode):
prompt_test = True if mode else False
print "prompt_test value in cli: %s" % prompt_test
@cli.command()
@click.option('--name',
prompt=prompt_test,
required=True
)
def test(name):
print "prompt_test value in test: %s" % prompt_test
print "test %s" % name
if __name__ == '__main__':
cli()
# Ok
# $ python __test_click --mode test
# prompt_test value in cli: True
# Name: aaa
# prompt_test value in test: True
# test aaa
# Not ok
# $ python __test_click.py test
# prompt_test value in cli: False <-- Looks good!
# Name: aaa <-- Unexpected prompting?
# prompt_test value in test: True <-- Why?
# test aaa
# Not ok
# $ python __test_click.py test --name aaa
# prompt_test value in cli: False <-- Ok
# prompt_test value in test: True <-- Why?
# test aaa
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment