click
interactively¶We all know that argparse
sucks, and click
is a common replacement.
See the click
documentation for the more information about Complex Arguments.
import click
@click.command()
@click.option('--count', default=1, help='Number of greetings.')
@click.option('--name', prompt='Your name',
help='The person to greet.')
def hello(count, name):
"""Simple program that greets NAME for a total of COUNT times."""
for x in range(count):
print('Hello! %s!' % name)
click.Context
from pytest import fixture
ctx = fixture(lambda: click.Context(hello))
click.Context.invoke
the command. _test_interactive_invocation = lambda ctx: ctx.invoke(hello, name="❤ deathbeds")
__name__ == '__main__' and _test_interactive_invocation(ctx())
Hello! ❤ deathbeds!