Skip to content
Myr

Merge pull request #1309 from icreatedanaccount/master

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

Formatting file option prompting to path only

authored by David Lord · committed by GitHub · parents 9ea9666, b830139 · Browse files · 3 files+31 added−2 removed
This commit

State

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

Diff stats

3 files+31 added−2 removed

  • tests:+18 added−0 removed
  • other:+13 added−2 removed

3 files+31 added−2 removed

modified:click/termui.py+11 added-2 removed
1import io2import os3import sys4import struct5import inspect6import itertools78from ._compat import raw_input, text_type, string_types, \8 isatty, strip_ansi, get_winterm_size, DEFAULT_COLUMNS, WIN9 isatty, strip_ansi, get_winterm_size, DEFAULT_COLUMNS, WIN10from .utils import echo11from .exceptions import Abort, UsageError12from .types import convert_type, Choice, Path13from .globals import resolve_color_default14from .utils import LazyFile151617# The prompt functions to use. The doc tools currently override these18# functions to customize how they work.
30 unmodified lines
49 prompt = text50 if type is not None and show_choices and isinstance(type, Choice):51 prompt += ' (' + ", ".join(map(str, type.choices)) + ')'52 if default is not None and show_default:51 prompt = '%s [%s]' % (prompt, default)53 prompt = '%s [%s]' % (prompt, _format_default(default))54 return prompt + suffix555657def _format_default(default):58 if isinstance(default, (io.IOBase, LazyFile)) and hasattr(default, "name"):59 return default.name6061 return default626364def prompt(text, default=None, hide_input=False, confirmation_prompt=False,65 type=None, value_proc=None, prompt_suffix=': ', show_default=True,66 err=False, show_choices=True):67 """Prompts a user for input. This is a convenience function that can
554 unmodified lines
modified:tests/test_termui.py+18 added
223 unmodified lines
224 result = runner.invoke(cli_without_choices, [], input='none')225 assert '(none, day, week, month)' not in result.output226227228@pytest.mark.parametrize(229 "file_kwargs",230 [231 {"mode": "rt"},232 {"mode": "rb"},233 {"lazy": True},234 ]235)236def test_file_prompt_default_format(runner, file_kwargs):237 @click.command()238 @click.option("-f", default=__file__, prompt="file", type=click.File(**file_kwargs))239 def cli(f):240 click.echo(f.name)241242 result = runner.invoke(cli)243 assert result.output == "file [{0}]: \n{0}\n".format(__file__)244245246def test_secho(runner):247 with runner.isolation() as outstreams:248 click.secho(None, nl=False)249 bytes = outstreams[0].getvalue()
64 unmodified lines
modified:CHANGES.rst+2 added
40 unmodified lines
41- Newlines in option help text are replaced with spaces before42 re-wrapping to avoid uneven line breaks. :issue:`834`43- ``MissingParameter`` exceptions are printable in the Python44 interpreter. :issue:`1139`45- Fix how default values for file-type options are shown during46 prompts. :issue:`914`474849Version 7.050-----------
540 unmodified lines