-
-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Arg::require_delimiter
is not enforced with positional arguments
#3308
Comments
clap 3's derive uses use clap::Parser;
#[derive(Debug, Parser)]
struct CliArgs {
#[clap(
required = true,
multiple_occurrences = false,
value_delimiter = ',',
require_delimiter = true
)]
list: Vec<u32>,
}
fn main() {
let CliArgs { list } = CliArgs::parse();
println!("List: {:?}", list);
} See #1772 for more context. I'm going to go ahead and close this, assuming this resolves the issue. If not, feel free to let us know! |
Hmm. This does indeed give me the intended behaviour; thank you for that. However I'm noticing that Anyways, this situation is just quite confusing from a user perspective IMO. I would imagine cleaning this up would cause quite a lot of API breakages and isn't ideal. So perhaps we can consider making some notes on this behaviour in the docs in the meanwhile? |
The distinction between occurrences and values is more clear with flags. We support both multiple occurrences and values for positional arguments because they can be used in slightly different ways. We also chose to go with occurrences for the You can have multiple occurrences and require a delimiter.
I am unsure what "clean up" there would be at this point. If you have ideas, feel free to share them.
What in particular are you thinking should be documented and where? In the derive reference we call out the meaning of |
Please complete the following tasks
Rust Version
1.58.0
Clap Version
3.0.9
Minimal reproducible code
Steps to reproduce the bug with the above code
cargo run -- 1 2 3 4 5
Actual Behaviour
List: [1, 2, 3, 4, 5]
Expected Behaviour
Parse should fail with
ErrorKind::UnknownArgument
, as shown in the example.Additional Context
OS is Manjaro and shell is Bash
Debug Output
The text was updated successfully, but these errors were encountered: