Skip to content
Myr

Merge branch 'Rovanion-master'

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Merges #496

authored by Markus Unterwaditzer · committed by Markus Unterwaditzer · parents 5a441c1, 13e045b · Browse files · 4 files+42 added−10 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

4 files+42 added−10 removed

  • tests:+20 added−0 removed
  • other:+22 added−10 removed

4 files+42 added−10 removed

modified:click/core.py+4 added-3 removed
1459 unmodified lines
1460 def __init__(self, param_decls=None, show_default=False,1461 prompt=False, confirmation_prompt=False,1462 hide_input=False, is_flag=None, flag_value=None,1463 multiple=False, count=False, allow_from_autoenv=True,1464 type=None, help=None, hidden=False, **attrs):1464 type=None, help=None, hidden=False, show_choices=True, **attrs):1465 default_is_missing = attrs.get('default', _missing) is _missing1466 Parameter.__init__(self, param_decls, type=type, **attrs)14671468 if prompt is True:
37 unmodified lines
1506 self.multiple = multiple1507 self.allow_from_autoenv = allow_from_autoenv1508 self.help = help1509 self.show_default = show_default1510 self.show_choices = show_choices15111512 # Sanity check for stuff we don't support1513 if __debug__:1514 if self.nargs < 0:
143 unmodified lines
1658 # differently.1659 if self.is_bool_flag:1660 return confirm(self.prompt, default)16611661 return prompt(self.prompt, default=default,1662 hide_input=self.hide_input,1662 return prompt(self.prompt, default=default, type=self.type,1663 hide_input=self.hide_input, show_choices=self.show_choices,1664 confirmation_prompt=self.confirmation_prompt,1665 value_proc=lambda x: self.process_value(ctx, x))16661667 def resolve_envvar_value(self, ctx):
87 unmodified lines
modified:click/termui.py+15 added-7 removed
4 unmodified lines
5from ._compat import raw_input, text_type, string_types, \6 isatty, strip_ansi, get_winterm_size, DEFAULT_COLUMNS, WIN7from .utils import echo8from .exceptions import Abort, UsageError9from .types import convert_type9from .types import convert_type, Choice10from .globals import resolve_color_default111213# The prompt functions to use. The doc tools currently override these
9 unmodified lines
23 import getpass24 return getpass.getpass(prompt)252627def _build_prompt(text, suffix, show_default=False, default=None):27def _build_prompt(text, suffix, show_default=False, default=None, show_choices=True, type=None):28 prompt = text29 if type is not None and show_choices and isinstance(type, Choice):30 prompt += ' (' + ", ".join(map(str, type.choices)) + ')'31 if default is not None and show_default:32 prompt = '%s [%s]' % (prompt, default)33 return prompt + suffix343534def prompt(text, default=None, hide_input=False,35 confirmation_prompt=False, type=None,36 value_proc=None, prompt_suffix=': ',37 show_default=True, err=False):36def prompt(text, default=None, hide_input=False, confirmation_prompt=False,37 type=None, value_proc=None, prompt_suffix=': ', show_default=True,38 err=False, show_choices=True):39 """Prompts a user for input. This is a convenience function that can40 be used to prompt a user for input later.4142 If the user aborts the input by sending a interrupt signal, this43 function will catch it and raise a :exc:`Abort` exception.4445 .. versionadded:: 7.046 Added the show_choices parameter.4748 .. versionadded:: 6.049 Added unicode support for cmd.exe on Windows.5051 .. versionadded:: 4.0
12 unmodified lines
64 :param prompt_suffix: a suffix that should be added to the prompt.65 :param show_default: shows or hides the default value in the prompt.66 :param err: if set to true the file defaults to ``stderr`` instead of67 ``stdout``, the same as with echo.68 :param show_choices: Show or hide choices if the passed type is a Choice.69 For example if type is a Choice of either day or week,70 show_choices is true and text is "Group by" then the71 prompt will be "Group by (day, week): ".72 """73 result = None7475 def prompt_func(text):
13 unmodified lines
8990 if value_proc is None:91 value_proc = convert_type(type, default)9285 prompt = _build_prompt(text, prompt_suffix, show_default, default)93 prompt = _build_prompt(text, prompt_suffix, show_default, default, show_choices, type)9495 while 1:96 while 1:97 value = prompt_func(prompt)
452 unmodified lines
modified:tests/test_termui.py+20 added
42 unmodified lines
43 result = runner.invoke(cli, [])44 assert result.exception is None454647def test_choices_list_in_prompt(runner, monkeypatch):48 @click.command()49 @click.option('-g', type=click.Choice(['none', 'day', 'week', 'month']),50 prompt=True)51 def cli_with_choices(g):52 pass5354 @click.command()55 @click.option('-g', type=click.Choice(['none', 'day', 'week', 'month']),56 prompt=True, show_choices=False)57 def cli_without_choices(g):58 pass5960 result = runner.invoke(cli_with_choices, [], input='none')61 assert '(none, day, week, month)' in result.output6263 result = runner.invoke(cli_without_choices, [], input='none')64 assert '(none, day, week, month)' not in result.output656667def test_secho(runner):68 with runner.isolation() as out:69 click.secho(None, nl=False)70 bytes = out.getvalue()
1 unmodified line
modified:CHANGES+3 added
6 unmodified lines
7-----------89(upcoming release with new features, release date to be decided)1011- The user is now presented with the available choices if prompt=True and12 type=click.Choice in a click.option. The choices are listed within13 parentthesis like 'Choose fruit (apple, orange): '.14- The exception objects now store unicode properly.15- Added the ability to hide commands and options from help.16- Added Float Range in Types.17- `secho`'s first argument can now be `None`, like in `echo`.
349 unmodified lines