-
-
Notifications
You must be signed in to change notification settings - Fork 1.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
Unexpected behavior with Vec<_>
argument types for positionals and options
#4655
Comments
So if I'm understanding correctly, you are wanting That was the old structopt behavior and we intentionally switched in #2993 as
|
Thanks for your answer, your reference helped me better understand. However what I find confusing is that |
The reason I didn't go into more nuance in the table is that
The derive reference is exclusive to what is unique in the derive. See #4090 for more details and further discussion on how to handle that problem. As for what cases to cover in other forms of documentation (cookbook, tutorials), the challenge is finding the right subset to cover and rely on the builder reference for the rest or else it becomes unmanageable. As I feel everything from this is expected behavior, I'm closing this out. We can continue the discussion if you want which can always lead to either this specific issue being re-opened or new issues being created. |
@epage I want to thank both of you for this discussion. I stumbled on it as I was looking for a way to collect all positional arguments regardless of where they appear in the argument list. I agree that named arguments should default to exactly 1 value, the way CLAP works by default now. I'd be very confused if a sudden I think CLAP works perfectly already. The "positional and option" (without "fix") in the list above makes the most sense and I am glad to see it's the default behavior. Thank you @lucatrv for the code demo that showed how to set that up. Just for reference, that's the following code: #[derive(Debug, Parser)]
struct Args {
positional: Vec<String>,
#[arg(long)]
option: Vec<String>,
}
fn main() {
let args = Args::parse();
dbg!(args);
} Command line: Result:
It's perfect. But I am also glad to know that it's possible to override the capturing via the |
Please complete the following tasks
Rust Version
1.66.1
Clap Version
4.1.1
Minimal reproducible code
Positional:
Option:
Option with fix:
Positional and option:
Positional and option with fix:
Steps to reproduce the bug with the above code
Positional:
cargo run -- a b c
Option:
cargo run -- --option a b c
Option with fix:
cargo run -- --option a b c
Positional and option:
cargo run -- a b c --option d e f
Positional and option with fix:
cargo run -- a b c --option d e f
Actual Behaviour
Positional:
Option:
Option with fix:
Positional and option:
Positional and option with fix:
Expected Behaviour
Positional:
Option:
Option with fix:
Positional and option:
Positional and option with fix:
Additional Context
As shown by the sample code above, when a positional argument is defined with
Vec<_>
type,num_args(0..)
is implied as expected. However when an option argument is defined with the same type,num_args(0..)
is not implied, so it needs to be added manually to achieve the same behavior (see code above "with fix"). This leads to unexpected behavior in particular when using both positional and option arguments. IMHOnum_args(0..)
should be implied for both positional and option arguments.Debug Output
No response
The text was updated successfully, but these errors were encountered: