How to tell whether boolean flag was set by user? #5487
Unanswered
lars-berger
asked this question in
Q&A
Replies: 1 comment
-
Got something working by using #[derive(Parser)]
#[clap(author, version, about, long_about = None)]
struct Foo {
#[arg(long)]
flag: bool,
#[clap(long, default_missing_value = "true", require_equals = true, num_args = 0..=1)]
flag_with_option: Option<bool>,
} With the above, the The CLI output is different than a normal boolean flag though. If someone knows a way around that, please let me know 👍
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Boolean flags have a great user experience by default, but a problem I'm running into is I can't figure out how to tell whether the user has explicitly specified the flag value. For my use case, the default arg value comes from an external source at runtime, and so I'd need to know whether the user has overridden this default.
My assumption was to change the type to
Option<bool>
, however, this makes the behavior inconsistent with the other boolean flags throughout our CLI.Is there a way to keep the
Option<bool>
type and make the behavior the same as a normal boolean flag?Beta Was this translation helpful? Give feedback.
All reactions