You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm setting the default_map from a config file, and it seems the values from the default_map are not correctly shown in the --help output if I set show_default=True on my option.
My Option looks like this:
@click.option("--long/--short","-l/-s",is_flag=True,show_default=True,help="show additional information like size and creation date",)
I initialize the default_map with a custom command class that I attach via the @click.command decorator like this @click.command(cls=ConfigAwareCommand)
The default_map value is in my example {'long': True}. In the --help output, the default value is shown like this
-l, --long / -s, --short show additional information like size and
creation date [default: short]
When executing the command, the default value from the default_map is used correctly (long defaults to True).
During debugging, I might have found the culprit inside src/click/core.py
elifself.is_bool_flagandself.secondary_opts:
# For boolean flags that have distinct True/False opts,# use the opt without prefix instead of the value.default_string=_split_opt(
(self.optsifself.defaultelseself.secondary_opts)[0]
)[1]
As you can see, self.default is used instead of the default_value variable that is initialized further above this code snippet.
If I change the part of the code above and use default_value instead of self.default the help output shows the correct default values from the default_map.
elifself.is_bool_flagandself.secondary_opts:
# For boolean flags that have distinct True/False opts,# use the opt without prefix instead of the value.default_string=_split_opt(
(self.optsifdefault_valueelseself.secondary_opts)[0]
)[1]
I am not sure if I do something wrong or if this is indeed a bug.
Environment:
Python version: 3.10.12
Click version: 8.1.7
The text was updated successfully, but these errors were encountered:
I'm setting the
default_map
from a config file, and it seems the values from thedefault_map
are not correctly shown in the--help
output if I setshow_default=True
on my option.My Option looks like this:
I initialize the
default_map
with a custom command class that I attach via the@click.command
decorator like this@click.command(cls=ConfigAwareCommand)
The
default_map
value is in my example{'long': True}
. In the--help
output, the default value is shown like thisWhen executing the command, the default value from the
default_map
is used correctly (long
defaults toTrue
).During debugging, I might have found the culprit inside src/click/core.py
As you can see,
self.default
is used instead of thedefault_value
variable that is initialized further above this code snippet.If I change the part of the code above and use
default_value
instead ofself.default
the help output shows the correct default values from thedefault_map
.I am not sure if I do something wrong or if this is indeed a bug.
Environment:
The text was updated successfully, but these errors were encountered: