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
Provenance
- Commit
2ddc9af- Tree
f7b1fe6- Author
icreatedanaccount <pierluc.boudreau@gmail.com>- Committer
David Lord <davidism@gmail.com>- Parent
9ea9666
5 files changed+27 added−2 removed
modified:click/_compat.py+2 added
154 unmodified lines155 156 157 if 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 lines261 return value262 else:263 import io264 text_type = str265+ file_type = io.TextIOWrapper266 raw_input = input267 string_types = (str,)268 int_types = (int,)269 range_type = range503 unmodified linesmodified:click/termui.py+8 added-2 removed
3 unmodified lines4 import inspect5 import itertools6 7 from ._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_type9 from .utils import echo10 from .exceptions import Abort, UsageError11 from .types import convert_type, Choice, Path12 from .globals import resolve_color_default34 unmodified lines47 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 + suffix53 54 55+def _format_default(default):56+ if isinstance(default, file_type):57+ default = default.name58+ return default59+60+61 def 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 can554 unmodified linesadded:tests/static/config.json+3 added
123{ "TEST_KEY": "foo"}modified:tests/test_termui.py+13 added
1 unmodified line2 import pytest3 4 import click5 import time6+import os7 8 import click._termui_impl9 from click._compat import WIN10 214 unmodified lines225 result = runner.invoke(cli_without_choices, [], input='none')226 assert '(none, day, week, month)' not in result.output227 228 229+def test_default_prompt_format(runner):230+ path_default = os.path.join(os.path.dirname(__file__), "static/config.json")231+232+ @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+ pass236+237+ result = runner.invoke(cli_with_text_io_wrapper_default, [])238+ assert result.output == 'file [%s]: \n' % path_default239+240+241 def test_secho(runner):242 with runner.isolation() as outstreams:243 click.secho(None, nl=False)244 bytes = outstreams[0].getvalue()64 unmodified linesmodified:CHANGES.rst+1 added
40 unmodified lines41 - 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`46 47 48 Version 7.049 -----------540 unmodified lines