consolekit.input
Input functions (prompt, choice etc.).
Functions:
|
Prompts a user for input. |
|
Prompts for confirmation (yes/no question). |
|
Prompts a user for input. |
|
Read a string from standard input, but prompt to standard error. |
-
choice(options, text='', default=None, prompt_suffix=': ', show_default=True, err=False, start_index=0)[source] Prompts a user for input.
If the user aborts the input by sending an interrupt signal, this function will catch it and raise a
click.Abortexception.- Parameters
text (
str) – The text to show for the prompt. Default''.default (
Optional[str]) – The index of the default value to use if the user does not enter anything. If this is not given it will prompt the user until aborted. DefaultNone.prompt_suffix (
str) – A suffix that should be added to the prompt. Default': '.show_default (
bool) – Shows or hides the default value in the prompt. DefaultTrue.err (
bool) – IfTruethe file defaults tostderrinstead ofstdout, the same as with echo. DefaultFalse.start_index (
int) – Ifoptionsis a list of values, sets the start index. Default0.
- Return type
- Overloads
-
confirm(text, default=False, abort=False, prompt_suffix=': ', show_default=True, err=False)[source] Prompts for confirmation (yes/no question).
If the user aborts the input by sending a interrupt signal this function will catch it and raise a
click.Abortexception.- Parameters
text (
str) – The question to ask.abort (
bool) – IfTruea negative answer aborts the exception by raisingclick.Abort. DefaultFalse.prompt_suffix (
str) – A suffix that should be added to the prompt. Default': '.show_default (
bool) – Shows or hides the default value in the prompt. DefaultTrue.err (
bool) – IfTruethe file defaults tostderrinstead ofstdout, the same as with echo. DefaultFalse.
-
prompt(text, default=None, hide_input=False, confirmation_prompt=False, type=None, value_proc=None, prompt_suffix=': ', show_default=True, err=False, show_choices=True)[source] Prompts a user for input.
If the user aborts the input by sending an interrupt signal, this function will catch it and raise a
click.Abortexception.- Parameters
text (
str) – The text to show for the prompt.default (
Optional[str]) – The default value to use if no input happens. If this is not given it will prompt until it is aborted. DefaultNone.hide_input (
bool) – IfTruethen the input value will be hidden. DefaultFalse.confirmation_prompt (
Union[bool,str]) – Asks for confirmation for the value. Can be set to a string instead ofTrueto customize the message. DefaultFalse.type (
Union[type,ParamType,Tuple[Union[type,ParamType], …],Callable[[str],Any],Callable[[Optional[str]],Any],None]) – The type to check the value against. DefaultNone.value_proc (
Optional[Callable[[Optional[str]],Any]]) – If this parameter is provided it must be a function that is invoked instead of the type conversion to convert a value. DefaultNone.prompt_suffix (
str) – A suffix that should be added to the prompt. Default': '.show_default (
bool) – Shows or hides the default value in the prompt. DefaultTrue.err (
bool) – IfTruethe file defaults tostderrinstead ofstdout, the same as withclick.echo(). DefaultFalse.show_choices (
bool) – Show or hide choices if the passed type is aclick.Choice. For example, if the choice is eitherdayorweek,show_choicesisTrueandtextis'Group by'then the prompt will be'Group by (day, week): '. DefaultTrue.
-
stderr_input(prompt='', file=<_io.TextIOWrapper name='<stdout>' mode='w' encoding='utf-8'>)[source] Read a string from standard input, but prompt to standard error.
The trailing newline is stripped. If the user hits EOF (Unix: Ctrl-D, Windows: Ctrl-Z+Return), raise
EOFError.On Unix, GNU readline is used if enabled.