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
Playing with click's ability to read environment variables and provide default values, I noticed that the order in which the variables are looked up seems wrong.
Here is what I expected (first variable found wins):
Retrieve the value from the CLI
Retrieve the value from the environment
Retrieve the default value
But here is what happened:
Retrieve the value from the CLI
Retrieve the default value
Retrieve the value from the environment
This seems wrong because the fact that I set default values should not prevent the environment lookup to happen.
How to reproduce
Create the precedence.py file:
importclick@click.command()@click.option('--name', help="Specify a name")defprec(name):
"""Greet the world."""click.echo(f'Hey {name}!')
if__name__=='__main__':
prec(auto_envvar_prefix='CLICK', default_map={'name': 'Stranger'})
I also see this as an issue. Quoting the documentation: "By default, the default value for a parameter is pulled from the default flag that is provided when it’s defined, but that’s not the only place defaults can be loaded from."
Currently, a default value provided via default_map takes precedence over environment variables, whereas environment variables take precedence over default values provided to click.option().
Activity
Fix variable precedence
chaoflow commentedon Apr 25, 2018
I also see this as an issue. Quoting the documentation: "By default, the default value for a parameter is pulled from the default flag that is provided when it’s defined, but that’s not the only place defaults can be loaded from."
Currently, a default value provided via default_map takes precedence over environment variables, whereas environment variables take precedence over default values provided to
click.option().Fix variable precedence
Fix variable precedence
Merge #1576
Merge #37
Update click to 7.0 (#97)