-
-
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
Bug when grouping positional args with options #1794
Comments
Yeah, this definitely looks like a bug. cc @CreepySkeleton |
Yes. I would expect all of the following to be valid invocations:
Working on the fix, might take a while. |
Small correction that |
Should be reopen. The usage output is still not correct. |
@ldm0 You were saying that the original fix is wrong. Can you point out a test case why it is wrong? |
@pksunkara Check this: let m = clap::App::new("hello")
.bin_name("deno")
.arg(Arg::new("pos1").takes_value(true))
.arg(Arg::new("option2").long("option2").takes_value(false))
.arg(Arg::new("pos2").takes_value(true))
.group(
ArgGroup::new("arg2")
.args(&["pos2", "option2"])
.required(true),
)
.try_get_matches();
dbg!(m); with:
You will notice it complains about conflict between |
@pksunkara has funded $20.00 to this issue.
|
Is this issue solved? |
Nope, currently. |
@ldm0 Can we focus on finishing this first? Or is it blocked by other stuff? |
@pksunkara @ldm0 The example above now passes on /// Test for https://github.com/clap-rs/clap/issues/1794.
#[test]
fn positional_args_with_options() {
let app = clap::App::new("hello")
.bin_name("deno")
.setting(AppSettings::AllowMissingPositional)
.arg(Arg::new("option1").long("option1").takes_value(false))
.arg(Arg::new("pos1").takes_value(true))
.group(
ArgGroup::new("arg1")
.args(&["pos1", "option1"])
.required(true),
)
.arg(Arg::new("pos2").takes_value(true));
let m = app.get_matches_from(&["deno", "--option1", "abcd"]);
assert!(m.is_present("option1"));
assert!(!m.is_present("pos1"));
assert!(m.is_present("pos2"));
assert_eq!(m.value_of("pos2"), Some("abcd"));
} And the usage is correctly shown as: USAGE:
deno <pos1|--option1> [pos2] This Lines 483 to 484 in 8b6034e
Is this intended?
|
@ldm0 what do you think? |
This works: use clap;
use clap::Arg;
use clap::ArgGroup;
use clap::AppSettings;
fn main() {
let app = clap::App::new("hello")
.bin_name("deno")
.setting(AppSettings::AllowMissingPositional)
.arg(Arg::new("option1").long("option1").takes_value(false))
.arg(Arg::new("pos1").takes_value(true))
.arg(Arg::new("pos2").takes_value(true))
.group(
ArgGroup::new("arg1")
.args(&["pos1", "option1"])
.required(true),
)
.get_matches();
} But this is not: use clap;
use clap::Arg;
use clap::ArgGroup;
use clap::AppSettings;
fn main() {
let app = clap::App::new("hello")
.bin_name("deno")
.setting(AppSettings::AllowMissingPositional)
.arg(Arg::new("option1").long("option1").takes_value(false))
.arg(Arg::new("pos1").takes_value(true))
.arg(Arg::new("pos2").takes_value(true))
.arg(Arg::new("pos3").takes_value(true))
.group(
ArgGroup::new("arg1")
.args(&["pos1", "pos2", "option1"])
.required(true),
)
.get_matches();
} error: The argument '--option1' cannot be used with '<pos1>'
USAGE:
deno [pos3] <pos1|pos2|--option1>
For more information try --help I don't think this issue can be closed now. |
I'm torn on this. Going to put this back in the design/decision status and going to remove the milestone. |
Rust Version
rustc 1.42.0 (b8cedc004 2020-03-09)
Code
Steps to reproduce the issue
cargo run -- -h
Affected Version of
clap*
2.33.0
Actual Behavior Summary
cargo run -- --option1 abcd
bindsabcd
topos1
and complains about conflict betweenoption1
andpos1
Blocks denoland/deno#4635, ref denoland/deno#4635 (comment).
Expected Behavior Summary
cargo run -- --option1 abcd
should bindabcd
topos2
. In other words, it should detect--option1
having been given as an option and accordingly skippos1
which--option1
is grouped with.--
If this is actually intended I welcome suggestions as to how I can get the above behaviour. But what else should be the semantics of grouping positional args with options?
IssueHunt Summary
Backers (Total: $20.00)
Become a backer now!
Or submit a pull request to get the deposits!
Tips
The text was updated successfully, but these errors were encountered: