Skip to content
Myr

Formatting file option prompting to path only

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

authored by icreatedanaccount · committed by David Lord · parent 9ea9666 · Browse files · 5 files+27 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

5 files+27 added−2 removed

  • tests:+16 added−0 removed
  • other:+11 added−2 removed

5 files+27 added−2 removed

modified:click/_compat.py+2 added
154 unmodified lines
155156157if PY2:158 text_type = unicode159 file_type = file160 raw_input = raw_input161 string_types = (str, unicode)162 int_types = (int, long)163 iteritems = lambda x: x.iteritems()
97 unmodified lines
261 return value262else:263 import io264 text_type = str265 file_type = io.TextIOWrapper266 raw_input = input267 string_types = (str,)268 int_types = (int,)269 range_type = range
503 unmodified lines
modified:click/termui.py+8 added-2 removed
3 unmodified lines
4import inspect5import itertools67from ._compat import raw_input, text_type, string_types, \8 isatty, strip_ansi, get_winterm_size, DEFAULT_COLUMNS, WIN8 isatty, strip_ansi, get_winterm_size, DEFAULT_COLUMNS, WIN, file_type9from .utils import echo10from .exceptions import Abort, UsageError11from .types import convert_type, Choice, Path12from .globals import resolve_color_default
34 unmodified lines
47 prompt = text48 if type is not None and show_choices and isinstance(type, Choice):49 prompt += ' (' + ", ".join(map(str, type.choices)) + ')'50 if default is not None and show_default:51 prompt = '%s [%s]' % (prompt, default)51 prompt = '%s [%s]' % (prompt, _format_default(default))52 return prompt + suffix535455def _format_default(default):56 if isinstance(default, file_type):57 default = default.name58 return default596061def prompt(text, default=None, hide_input=False, confirmation_prompt=False,62 type=None, value_proc=None, prompt_suffix=': ', show_default=True,63 err=False, show_choices=True):64 """Prompts a user for input. This is a convenience function that can
554 unmodified lines
added:tests/static/config.json+3 added
modified:tests/test_termui.py+13 added
1 unmodified line
2import pytest34import click5import time6import os78import click._termui_impl9from click._compat import WIN10
214 unmodified lines
225 result = runner.invoke(cli_without_choices, [], input='none')226 assert '(none, day, week, month)' not in result.output227228229def test_default_prompt_format(runner):230 path_default = os.path.join(os.path.dirname(__file__), "static/config.json")231232 @click.command()233 @click.option('-f', default=path_default, prompt='file', type=click.File('r'))234 def cli_with_text_io_wrapper_default(f):235 pass236237 result = runner.invoke(cli_with_text_io_wrapper_default, [])238 assert result.output == 'file [%s]: \n' % path_default239240241def test_secho(runner):242 with runner.isolation() as outstreams:243 click.secho(None, nl=False)244 bytes = outstreams[0].getvalue()
64 unmodified lines
modified:CHANGES.rst+1 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- File option prompting now displays path only. :issue:`914`464748Version 7.049-----------
540 unmodified lines