diff options
author | Nicholas Wiles <nwiles@google.com> | 2017-10-05 17:37:50 -0700 |
---|---|---|
committer | Nicholas Wiles <nwiles@google.com> | 2017-10-05 17:37:50 -0700 |
commit | 29df08935d366ee8f3d7e9aea2a29b434a94124b (patch) | |
tree | 572416f717fbcb5e53c25a8fdc919ff22d562a98 | |
parent | 65da5cc5c4b2e75037811c76d73f742e7ef033c5 (diff) | |
parent | 752ff79d680fceb26d2a93f1eef376d90823ec47 (diff) | |
download | click-29df08935d366ee8f3d7e9aea2a29b434a94124b.tar.gz |
Merge commit '752ff79d680fceb26d2a93f1eef376d90823ec47' into feature/790
# Conflicts:
# CHANGES
-rw-r--r-- | CHANGES | 1 | ||||
-rw-r--r-- | click/_unicodefun.py | 2 | ||||
-rw-r--r-- | click/globals.py | 2 | ||||
-rw-r--r-- | click/types.py | 14 | ||||
-rw-r--r-- | docs/parameters.rst | 4 | ||||
-rw-r--r-- | setup.cfg | 3 | ||||
-rw-r--r-- | tests/test_basic.py | 22 |
7 files changed, 37 insertions, 11 deletions
@@ -25,6 +25,7 @@ Version 7.0 a Unix shell command. See #664. - Fix bug that caused bashcompletion to give inproper completions on chained commands. See #774. +- 't' and 'f' are now converted to True and False. - Fix bug that caused bashcompletion to give inproper completions on chained commands when a required option/argument was being completed. See #790. diff --git a/click/_unicodefun.py b/click/_unicodefun.py index 998b2cb..e09e18b 100644 --- a/click/_unicodefun.py +++ b/click/_unicodefun.py @@ -116,5 +116,5 @@ def _verify_python3_env(): raise RuntimeError('Click will abort further execution because Python 3 ' 'was configured to use ASCII as encoding for the ' - 'environment. Consult http://click.pocoo.org/python3/' + 'environment. Consult http://click.pocoo.org/python3/ ' 'for mitigation steps.' + extra) diff --git a/click/globals.py b/click/globals.py index 14338e6..843b594 100644 --- a/click/globals.py +++ b/click/globals.py @@ -9,7 +9,7 @@ def get_current_context(silent=False): access the current context object from anywhere. This is a more implicit alternative to the :func:`pass_context` decorator. This function is primarily useful for helpers such as :func:`echo` which might be - interested in changing it's behavior based on the current context. + interested in changing its behavior based on the current context. To push the current context, :meth:`Context.scope` can be used. diff --git a/click/types.py b/click/types.py index 3eb5fac..fab63e4 100644 --- a/click/types.py +++ b/click/types.py @@ -274,9 +274,9 @@ class BoolParamType(ParamType): if isinstance(value, bool): return bool(value) value = value.lower() - if value in ('true', '1', 'yes', 'y'): + if value in ('true', 't,' '1', 'yes', 'y'): return True - elif value in ('false', '0', 'no', 'n'): + elif value in ('false', 'f', '0', 'no', 'n'): return False self.fail('%s is not a valid boolean' % value, param, ctx) @@ -402,11 +402,11 @@ class Path(ParamType): supposed to be done by the shell only. :param allow_dash: If this is set to `True`, a single dash to indicate standard streams is permitted. - :param type: optionally a string type that should be used to - represent the path. The default is `None` which - means the return value will be either bytes or - unicode depending on what makes most sense given the - input data Click deals with. + :param path_type: optionally a string type that should be used to + represent the path. The default is `None` which + means the return value will be either bytes or + unicode depending on what makes most sense given the + input data Click deals with. """ envvar_list_splitter = os.path.pathsep diff --git a/docs/parameters.rst b/docs/parameters.rst index e545343..9e5587e 100644 --- a/docs/parameters.rst +++ b/docs/parameters.rst @@ -47,8 +47,8 @@ different behavior and some are supported out of the box: ``bool`` / :data:`click.BOOL`: A parameter that accepts boolean values. This is automatically used - for boolean flags. If used with string values ``1``, ``yes``, ``y`` - and ``true`` convert to `True` and ``0``, ``no``, ``n`` and ``false`` + for boolean flags. If used with string values ``1``, ``yes``, ``y``, ``t`` + and ``true`` convert to `True` and ``0``, ``no``, ``n``, ``f`` and ``false`` convert to `False`. :data:`click.UUID`: @@ -3,3 +3,6 @@ universal=1 [metadata] license_file = LICENSE + +[tool:pytest] +addopts = -p no:warnings diff --git a/tests/test_basic.py b/tests/test_basic.py index ec4df7d..573bcbf 100644 --- a/tests/test_basic.py +++ b/tests/test_basic.py @@ -180,6 +180,28 @@ def test_boolean_option(runner): assert result.output == '%s\n' % (default) +def test_boolean_conversion(runner): + for default in True, False: + @click.command() + @click.option('--flag', default=default, type=bool) + def cli(flag): + click.echo(flag) + + for value in 'true', 't,' '1', 'yes', 'y': + result = runner.invoke(cli, ['--flag', value]) + assert not result.exception + assert result.output == 'True\n' + + for value in 'false', 'f', '0', 'no', 'n': + result = runner.invoke(cli, ['--flag', value]) + assert not result.exception + assert result.output == 'False\n' + + result = runner.invoke(cli, []) + assert not result.exception + assert result.output == '%s\n' % default + + def test_file_option(runner): @click.command() @click.option('--file', type=click.File('w')) |