Skip to content
Myr

customize confirmation prompt

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

authored by Saif807380 · committed by David Lord · parent 0805f60 · Browse files · 4 files+52 added−13 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+52 added−13 removed

  • tests:+24 added−0 removed
  • other:+28 added−13 removed

4 files+52 added−13 removed

modified:src/click/core.py+4 added-2 removed
2144 unmodified lines
2145 are not shown.2146 :param prompt: if set to `True` or a non empty string then the user will be2147 prompted for input. If set to `True` the prompt will be the2148 option name capitalized.2149 :param confirmation_prompt: if set then the value will need to be confirmed2150 if it was prompted for.2149 :param confirmation_prompt: Prompt a second time to confirm the2150 value if it was prompted for. Can be set to a string instead of2151 ``True`` to customize the message.2152 :param prompt_required: If set to ``False``, the user will be2153 prompted for input only when the option was specified as a flag2154 without a value.2155 :param hide_input: if this is `True` then the input on the prompt will be
47 unmodified lines
2203 elif prompt is False:2204 prompt_text = None2205 else:2206 prompt_text = prompt22072208 self.prompt = prompt_text2209 self.confirmation_prompt = confirmation_prompt2210 self.prompt_required = prompt_required2211 self.hide_input = hide_input
393 unmodified lines
modified:src/click/termui.py+23 added-11 removed
83 unmodified lines
8485 If the user aborts the input by sending a interrupt signal, this86 function will catch it and raise a :exc:`Abort` exception.8788 .. versionadded:: 7.089 Added the show_choices parameter.9091 .. versionadded:: 6.092 Added unicode support for cmd.exe on Windows.9394 .. versionadded:: 4.095 Added the `err` parameter.9688 :param text: the text to show for the prompt.89 :param default: the default value to use if no input happens. If this90 is not given it will prompt until it's aborted.91 :param hide_input: if this is set to true then the input value will92 be hidden.102 :param confirmation_prompt: asks for confirmation for the value.93 :param confirmation_prompt: Prompt a second time to confirm the94 value. Can be set to a string instead of ``True`` to customize95 the message.96 :param type: the type to use to check the value against.97 :param value_proc: if this parameter is provided it's a function that98 is invoked instead of the type conversion to99 convert a value.
4 unmodified lines
104 :param show_choices: Show or hide choices if the passed type is a Choice.105 For example if type is a Choice of either day or week,106 show_choices is true and text is "Group by" then the107 prompt will be "Group by (day, week): ".108109 .. versionadded:: 8.0110 ``confirmation_prompt`` can be a custom string.111112 .. versionadded:: 7.0113 Added the ``show_choices`` parameter.114115 .. versionadded:: 6.0116 Added unicode support for cmd.exe on Windows.117118 .. versionadded:: 4.0119 Added the `err` parameter.120121 """122 result = None123124 def prompt_func(text):
17 unmodified lines
142 prompt = _build_prompt(143 text, prompt_suffix, show_default, default, show_choices, type144 )145146 if confirmation_prompt:147 if confirmation_prompt is True:148 confirmation_prompt = "Repeat for confirmation"149150 confirmation_prompt = _build_prompt(confirmation_prompt, prompt_suffix)151152 while 1:153 while 1:154 value = prompt_func(prompt)155 if value:
11 unmodified lines
167 continue168 if not confirmation_prompt:169 return result170 while 1:159 value2 = prompt_func("Repeat for confirmation: ")171 value2 = prompt_func(confirmation_prompt)172 if value2:173 break174 if value == value2:175 return result
558 unmodified lines
modified:tests/test_termui.py+24 added
444 unmodified lines
445446 result = runner.invoke(cli, args=args, input="prompt", standalone_mode=False)447 assert result.exception is None448 assert result.return_value == expect449450451@pytest.mark.parametrize(452 ("prompt", "input", "expect"),453 [454 (True, "password\npassword", "password"),455 ("Confirm Password", "password\npassword\n", "password"),456 (False, None, None),457 ],458)459def test_confirmation_prompt(runner, prompt, input, expect):460 @click.command()461 @click.option(462 "--password", prompt=prompt, hide_input=True, confirmation_prompt=prompt463 )464 def cli(password):465 return password466467 result = runner.invoke(cli, input=input, standalone_mode=False)468 assert result.exception is None469 assert result.return_value == expect470471 if prompt == "Confirm Password":472 assert "Confirm Password: " in result.output
modified:CHANGES.rst+1 added
168 unmodified lines
169- ``click.confirm()`` will prompt until input is given if called with170 ``default=None``. :issue:`1381`171- Option prompts validate the value with the option's callback in172 addition to its type. :issue:`457`173- ``confirmation_prompt`` can be set to a custom string. :issue:`723`174- Allow styled output in Jupyter on Windows. :issue:`1271`175176177Version 7.1.2
636 unmodified lines