Open xobs opened 2 months ago
I don't think I quite understand your concern.
You are telling clap that --verbose
should have a V
environment variable associated with it. Most of the other changes you mention seem tangential to that; the main problem seems to be about whether 1
is accepted for --verbose
s V
. The default value_parser
for bool
is BoolValueParser
. You might be interested in value_parser = BoolishValueParser
.
Isn't it the case where bool
types will set the value to true
if they exist? If so, it shouldn't matter whether the value is 1
, true
, or something else.
The issue is that it does this normally, unless you have both global = true
and env = "V"
.
I think what happens is that with global = true
and env = "V"
it checks both the environment AND the flag, but with only one or the other it short-circuits if the -v
argument is present.
The short-circuit is what was confusing me -- why would global = true
cause it to evaluate both command line flags and environment variables, even if the command line flag exists? If that's a known behaviour, then that explains this issue and it can be closed.
The short-circuit is what was confusing me -
Thanks for the clarification
Currently, we parse a command at a time, including
and then we process globals.
There are subtle aspects to this that will need care to resolve. In particular, a solution should keep in mind some of our other issues around globals
Please complete the following tasks
Rust Version
rustc 1.79.0 (129f3b996 2024-06-10)
Clap Version
4.5.9
Minimal reproducible code
Steps to reproduce the bug with the above code
Cargo.toml:
Run with:
Afterwards, remove
global = true
ORenv = "V"
and observe that it works.Actual Behaviour
Expected Behaviour
When removing
global = true
orenv = "V"
it works correctly:Additional Context
The purpose of this code is to allow passing
V=1
to a function that sets up logging before clap is run. Sinceenv_logger
cannot change its level once it's initialized, we need to do this odd dance.The issue here is that behaviour changes with
env = "V"
andglobal = true
. It seems to only happen when the following three things are true:global = true
ANDenv = "V"
-v
is specifiedIf any condition is missing, the issue does not trigger.
Debug Output