consolekit.input

Input functions (prompt, choice etc.).

Functions:

choice(​options[, text, default, …])

Prompts a user for input.

confirm(​text[, default, abort, …])

Prompts for confirmation (yes/no question).

prompt(​text[, default, hide_input, …])

Prompts a user for input.

stderr_input(​[prompt, file])

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.Abort exception.

Parameters
  • options (Union[List[str], Mapping[str, str]])

  • 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. Default None.

  • 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. Default True.

  • err (bool) – If True the file defaults to stderr instead of stdout, the same as with echo. Default False.

  • start_index (int) – If options is a list of values, sets the start index. Default 0.

Return type

Union[str, int]

Overloads
  • choice(options: List[str], text = …, default = …, prompt_suffix = …, show_default = …, err = …, start_index = … ) -> int

  • choice(options: Mapping[str, str], text = …, default = …, prompt_suffix = …, show_default = …, err = …, start_index = … ) -> str

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.Abort exception.

Parameters
  • text (str) – The question to ask.

  • default (bool) – The default for the prompt. Default False.

  • abort (bool) – If True a negative answer aborts the exception by raising click.Abort. Default False.

  • 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. Default True.

  • err (bool) – If True the file defaults to stderr instead of stdout, the same as with echo. Default False.

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.Abort exception.

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. Default None.

  • hide_input (bool) – If True then the input value will be hidden. Default False.

  • confirmation_prompt (Union[bool, str]) – Asks for confirmation for the value. Can be set to a string instead of True to customize the message. Default False.

  • type (Union[type, ParamType, Tuple[Union[type, ParamType], …], Callable[[str], Any], Callable[[Optional[str]], Any], None]) – The type to check the value against. Default None.

  • 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. Default None.

  • 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. Default True.

  • err (bool) – If True the file defaults to stderr instead of stdout, the same as with click.echo(). Default False.

  • show_choices (bool) – Show or hide choices if the passed type is a click.Choice. For example, if the choice is either day or week, show_choices is True and text is 'Group by' then the prompt will be 'Group by (day, week): '. Default True.

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.

The prompt string, if given, is printed to stderr without a trailing newline before reading.

Return type

str