Merge commit '752ff79d680fceb26d2a93f1eef376d90823ec47' into feature/790
Before adoption: this commit came in with the history the project adopted, so no landing records it.
# Conflicts: # CHANGES
authored by Nicholas Wiles · committed by Nicholas Wiles · parents 65da5cc, 752ff79 · Browse files · 7 files·+37 added−11 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
7 files+37 added−11 removed
- tests:+22 added−0 removed
- other:+15 added−11 removed
Provenance
- Commit
29df089- Tree
572416f- Author
Nicholas Wiles <nwiles@google.com>- Committer
Nicholas Wiles <nwiles@google.com>- Parent 1
65da5cc- Parent 2
752ff79
7 files changed+37 added−11 removed
modified:click/_unicodefun.py+1 added-1 removed
114 unmodified lines115 ) % bad_locale116 117 raise RuntimeError('Click will abort further execution because Python 3 '118 'was configured to use ASCII as encoding for the '119- 'environment. Consult http://click.pocoo.org/python3/'119+ 'environment. Consult http://click.pocoo.org/python3/ '120 'for mitigation steps.' + extra)modified:click/globals.py+1 added-1 removed
7 unmodified lines8 """Returns the current click context. This can be used as a way to9 access the current context object from anywhere. This is a more implicit10 alternative to the :func:`pass_context` decorator. This function is11 primarily useful for helpers such as :func:`echo` which might be12- interested in changing it's behavior based on the current context.12+ interested in changing its behavior based on the current context.13 14 To push the current context, :meth:`Context.scope` can be used.15 16 .. versionadded:: 5.032 unmodified linesmodified:click/types.py+7 added-7 removed
272 unmodified lines273 def convert(self, value, param, ctx):274 if isinstance(value, bool):275 return bool(value)276 value = value.lower()277- if value in ('true', '1', 'yes', 'y'):277+ if value in ('true', 't,' '1', 'yes', 'y'):278 return True279- elif value in ('false', '0', 'no', 'n'):279+ elif value in ('false', 'f', '0', 'no', 'n'):280 return False281 self.fail('%s is not a valid boolean' % value, param, ctx)282 283 def __repr__(self):117 unmodified lines401 will not expand a tilde-prefix, as this is402 supposed to be done by the shell only.403 :param allow_dash: If this is set to `True`, a single dash to indicate404 standard streams is permitted.405- :param type: optionally a string type that should be used to406- represent the path. The default is `None` which407- means the return value will be either bytes or408- unicode depending on what makes most sense given the409- input data Click deals with.405+ :param path_type: optionally a string type that should be used to406+ represent the path. The default is `None` which407+ means the return value will be either bytes or408+ unicode depending on what makes most sense given the409+ input data Click deals with.410 """411 envvar_list_splitter = os.path.pathsep412 413 def __init__(self, exists=False, file_okay=True, dir_okay=True,178 unmodified linesmodified:docs/parameters.rst+2 added-2 removed
45 unmodified lines46 A parameter that only accepts floating point values.47 48 ``bool`` / :data:`click.BOOL`:49 A parameter that accepts boolean values. This is automatically used50- for boolean flags. If used with string values ``1``, ``yes``, ``y``51- and ``true`` convert to `True` and ``0``, ``no``, ``n`` and ``false``50+ for boolean flags. If used with string values ``1``, ``yes``, ``y``, ``t``51+ and ``true`` convert to `True` and ``0``, ``no``, ``n``, ``f`` and ``false``52 convert to `False`.53 54 :data:`click.UUID`:55 A parameter that accepts UUID values. This is not automatically68 unmodified linesmodified:tests/test_basic.py+22 added
178 unmodified lines179 assert not result.exception180 assert result.output == '%s\n' % (default)181 182 183+def test_boolean_conversion(runner):184+ for default in True, False:185+ @click.command()186+ @click.option('--flag', default=default, type=bool)187+ def cli(flag):188+ click.echo(flag)189+190+ for value in 'true', 't,' '1', 'yes', 'y':191+ result = runner.invoke(cli, ['--flag', value])192+ assert not result.exception193+ assert result.output == 'True\n'194+195+ for value in 'false', 'f', '0', 'no', 'n':196+ result = runner.invoke(cli, ['--flag', value])197+ assert not result.exception198+ assert result.output == 'False\n'199+200+ result = runner.invoke(cli, [])201+ assert not result.exception202+ assert result.output == '%s\n' % default203+204+205 def test_file_option(runner):206 @click.command()207 @click.option('--file', type=click.File('w'))208 def input(file):290 unmodified linesmodified:CHANGES+1 added
23 unmodified lines24 - `CliRunner.invoke` now may receive `args` as a string representing25 a Unix shell command. See #664.26 - Fix bug that caused bashcompletion to give inproper completions on 27 chained commands. See #774.28+- 't' and 'f' are now converted to True and False. 29 - Fix bug that caused bashcompletion to give inproper completions on30 chained commands when a required option/argument was being completed.31 See #790.32 357 unmodified linesmodified:setup.cfg+3 added
1 unmodified line2 universal=13 4 [metadata]5 license_file = LICENSE6+7+[tool:pytest]8+addopts = -p no:warnings