Prompts
Parser[T]
¶
A function taking in any value and returns a value of type T
. This parser
can be a user defined function, a built-in type like str
, int
, etc., or a parser
from a library.
confirm
¶
def confirm(
text: str,
*,
default: bool | Unset = UNSET,
max_attempts: int = MAX_ATTEMPTS,
abort: bool = False,
) -> bool:
Parameters:
text
: the text to display to the user when asking for inputdefault
: optionally set a default value that the user can immediately acceptmax_attempts
: how many times to ask the user before giving up and raisingabort
: if a user answers "no", it will raise aAbortException
prompt
¶
def prompt(
text: str,
default: T | Unset = UNSET,
parser: Parser[T] = str,
hide_input: bool = False,
max_attempts: int = MAX_ATTEMPTS,
) -> T:
Parameters:
text
: the text to display to the user when asking for inputdefault
: optionally set a default value that the user can immediately acceptparser
: a function that parses in the user input as a string and returns the parsed value or raiseshide_input
: whether the input shouldn't be displayed as the user types (for passwords, API keys, etc.)max_attempts
: how many times to ask the user before giving up and raising