Require a value for flag even with default_value #2083
-
Make sure you completed the following tasks
Describe your use caseConsider this program with clap 3.0 beta: use clap::Clap;
#[derive(Clap, Debug)]
struct Opts {
#[clap(long)]
batch_size: usize
}
fn main() {
dbg!(Opts::parse());
} Invoking this program with
That's nice 👍. Now, consider I want to add a default value:
Now I can invoke as However, I can now also invoke the original form Describe the solution you'd likeTo me, a user writing So I think that (To me, having a Alternatives, if applicableDiscussion in #1545 implies that this behaviour is supposedly expected, and so clap could consider doing nothing here. However, I would ask you to please reconsider this (at least for the clap 3.0 derive macro, which is why I've opened this as a separate issue). In my eyes, this behaviour allows users to silently make mistakes while using my CLI, e.g. by a malformed shell subsitution. |
Beta Was this translation helpful? Give feedback.
Replies: 6 comments
-
I'd like to lend my support to this proposal. I often - both in private and at work - experience this footgun situation when helping others with their scripts:
|
Beta Was this translation helpful? Give feedback.
-
@CreepySkeleton Can you please take a look at this? |
Beta Was this translation helpful? Give feedback.
-
We have #[clap(long, default_value = "5", default_missing_value = "5")] |
Beta Was this translation helpful? Give feedback.
-
@pksunkara thanks but With the suggested
What I want my program to do:
|
Beta Was this translation helpful? Give feedback.
-
Have you tried it with the latest master? It should fail now since you haven't added |
Beta Was this translation helpful? Give feedback.
-
@pksunkara I found the same issue on master, created a PR #2172 to fix it! 🚀 |
Beta Was this translation helpful? Give feedback.
@pksunkara I found the same issue on master, created a PR #2172 to fix it! 🚀