Skip to content
Myr

option with multiple and flag_value replaces internal placeholder

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

authored by Ivan Kapelyukhin · committed by David Lord · parent 0905156 · Browse files · 3 files+33 added−0 removed
This commit

State

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

Trailers

  • Co-authored-by: David Lord <davidism@gmail.com>

Diff stats

3 files+33 added−0 removed

  • tests:+23 added−0 removed
  • other:+10 added−0 removed

3 files+33 added−0 removed

modified:src/click/core.py+8 added
2851 unmodified lines
2852 else:2853 value = self.flag_value2854 source = ParameterSource.COMMANDLINE28552856 elif (2857 self.multiple2858 and value is not None2859 and any(v is _flag_needs_value for v in value)2860 ):2861 value = [self.flag_value if v is _flag_needs_value else v for v in value]2862 source = ParameterSource.COMMANDLINE28632864 # The value wasn't set, or used the param's default, prompt if2865 # prompting is enabled.2866 elif (2867 source in {None, ParameterSource.DEFAULT}
84 unmodified lines
modified:tests/test_options.py+23 added
790 unmodified lines
791 result = runner.invoke(cli, args, standalone_mode=False, catch_exceptions=False)792 assert result.return_value == expect793794795def test_multiple_option_with_optional_value(runner):796 cli = click.Command(797 "cli",798 params=[799 click.Option(["-f"], is_flag=False, flag_value="flag", multiple=True),800 click.Option(["-a"]),801 click.Argument(["b"], nargs=-1),802 ],803 callback=lambda **kwargs: kwargs,804 )805 result = runner.invoke(806 cli,807 ["-f", "-f", "other", "-f", "-a", "1", "a", "b"],808 standalone_mode=False,809 catch_exceptions=False,810 )811 assert result.return_value == {812 "f": ("flag", "other", "flag"),813 "a": "1",814 "b": ("a", "b"),815 }816817818def test_type_from_flag_value():819 param = click.Option(["-a", "x"], default=True, flag_value=4)820 assert param.type is click.INT821 param = click.Option(["-b", "x"], flag_value=8)
20 unmodified lines
modified:CHANGES.rst+2 added
22 unmodified lines
23- An option with ``count=True`` will not show "[x>=0]" in help text.24 :issue:`2072`25- Default values are not cast to the parameter type twice during26 processing. :issue:`2085`27- Options with ``multiple`` and ``flag_value`` use the flag value28 instead of leaving an internal placeholder. :issue:`2001`293031Version 8.0.132-------------
889 unmodified lines