Skip to content
Myr

Merge pull request #1301 from kporangehat/issue_1287_bool_flags

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

for #1287: allow bool type with bool flags

authored by David Lord · committed by GitHub · parents 7817ae6, c7bd8d4 · Browse files · 3 files+14 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+14 added−2 removed

  • tests:+10 added−0 removed
  • other:+4 added−2 removed

3 files+14 added−2 removed

modified:click/core.py+2 added-2 removed
1604 unmodified lines
1605 flag_value = not self.default1606 self.is_flag = is_flag1607 self.flag_value = flag_value1608 if self.is_flag and isinstance(self.flag_value, bool) \1609 and type is None:1609 and type in [None, bool]:1610 self.type = BOOL1611 self.is_bool_flag = True1612 else:1613 self.is_bool_flag = False
155 unmodified lines
17691770 return ((any_prefix_is_slash and '; ' or ' / ').join(rv), help)17711772 def get_default(self, ctx):1773 # If we're a non boolean flag out default is more complex because1773 # If we're a non boolean flag our default is more complex because1774 # we need to look at all flags in the same group to figure out1775 # if we're the the default one in which case we return the flag1776 # value as default.1777 if self.is_flag and not self.is_bool_flag:
116 unmodified lines
modified:tests/test_options.py+10 added
461 unmodified lines
462 assert 'I am a help text' in result.output463 assert 'you wont see me' not in result.output464465466def test_bool_flag_with_type(runner):467 @click.command()468 @click.option('--shout/--no-shout', default=False, type=bool)469 def cmd(shout):470 pass471472 result = runner.invoke(cmd)473 assert not result.exception474475476def test_aliases_for_flags(runner):477 @click.command()478 @click.option('--warnings/--no-warnings', ' /-W', default=True)479 def cli(warnings):
46 unmodified lines
modified:CHANGES.rst+2 added
34 unmodified lines
35 ``result.stderr`` is empty it will not raise a ``ValueError``.36 :issue:`1193`37- Remove the unused ``mix_stderr`` parameter from38 ``CliRunner.invoke``. :issue:`1435`39- Fix ``TypeError`` raised when using bool flags and specifying40 ``type=bool``. :issue:`1287`414243Version 7.044-----------
540 unmodified lines