Closed
Description
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:
import click
@click.command()
@click.option('--name', help="Specify a name")
def prec(name):
"""Greet the world."""
click.echo(f'Hey {name}!')
if __name__ == '__main__':
prec(auto_envvar_prefix='CLICK', default_map={'name': 'Stranger'})
Then run:
$ export CLICK_NAME=Tiger
$ python precedence.py --name Joe
Hey Joe!
$ python precedence.py
Hey Stranger!
Then remove the default_map
argument from the command call and you get:
$ export CLICK_NAME=Tiger
$ python precedence.py --name Joe
Hey Joe!
$ python precedence.py
Hey Tiger!
Versions
Python: 3.6.3
Click: 6.7
Metadata
Metadata
Assignees
Labels
No labels