click allows you to prompt the user if command line parameter is missing, but the functionality is minimal. I discovered that I can do WAY better if pass questionary callables as a default.
Describe the solution
Example program:
import click
import questionary
def asyncquestiontest():
"""Prompts for color, but times out after 3 seconds and defaults to black"""
import asyncio
async def timeoutquestion():
try:
return await asyncio.wait_for(
questionary.text("What's your favorite color?").ask_async(), 3
)
except:
print("defaulting to black")
return "black"
return asyncio.run(timeoutquestion())
@click.command()
@click.option("--username", default=questionary.text("What's your username").ask)
@click.option("--color", default=asyncquestiontest)
def hello(username, color):
"""A simple response to the user prompts above"""
click.echo(f"Hello, {username}! I like {color}, too!")
hello()
Describe the problem
The more I use
questionary
, the more I love it.click
allows you to prompt the user if command line parameter is missing, but the functionality is minimal. I discovered that I can do WAY better if passquestionary
callables as a default.Describe the solution
Example program:
Alternatives considered
No response