Skip to content

Conversation

chips-wq
Copy link
Contributor

@click.option('--upper', flag_value='upper', envvar='UPPER')
def cmd(upper):
    click.echo(upper)
    return upper

Default use

The expectation of the above code when running python cmd.py --upper is to print to stdout upper (the flag value). This is default behaviour and works correctly.

Environment variable use

What is the expectation when we run UPPER=32 python cmd.py ?

The program should still print to the screen upper, because that is the flag_value and there exists an env variable defined with the name UPPER, yet it actually prints 32, the value of the environment variable, which i don't believe is intended.

I also added a test for this functionality called test_envvar_flag_value
fixes #2746

@chips-wq chips-wq changed the base branch from main to 8.1.x October 13, 2024 20:49
@AndreasBackx AndreasBackx added this to the 8.2.0 milestone Oct 26, 2024
@AndreasBackx AndreasBackx mentioned this pull request Oct 26, 2024
34 tasks
@AndreasBackx AndreasBackx changed the base branch from stable to main November 3, 2024 14:33
@AndreasBackx AndreasBackx merged commit 1787497 into pallets:main Nov 3, 2024
12 checks passed
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 20, 2024
kdeldycke added a commit that referenced this pull request Jul 1, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

flag_value is not taken into account with envvar
2 participants