Skip to content
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

Argument conflict ignored on globals specified at different levels #5335

Closed
2 tasks done
abesto opened this issue Feb 1, 2024 · 2 comments
Closed
2 tasks done

Argument conflict ignored on globals specified at different levels #5335

abesto opened this issue Feb 1, 2024 · 2 comments
Labels
C-bug Category: Updating dependencies

Comments

@abesto
Copy link

abesto commented Feb 1, 2024

Please complete the following tasks

Rust Version

1.75.0

Clap Version

4.4.12

Minimal reproducible code

https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=8fa6a4126712c787b6170a7663e929e7

use clap::{Parser, Subcommand, Args};

#[derive(Args, Debug)]
#[group(multiple = false)]
struct Group {
    #[clap(short, global = true)]
    a: bool,
    #[clap(short, global = true)]
    b: bool,
}

#[derive(Subcommand, Debug)]
enum Sub {
    Foo
}

#[derive(Parser, Debug)]
struct Cli {
    #[clap(flatten)]
    g: Group,
    #[command(subcommand)]
    sub: Sub,
}

pub fn main() -> anyhow::Result<()> {
    dbg!(Cli::try_parse_from(["cli", "-a", "foo", "-b"])?);
    dbg!(Cli::try_parse_from(["cli", "-a", "-b", "foo"])?);
    Ok(())
}

Steps to reproduce the bug with the above code

cargo run / run the Playground snippet

Actual Behaviour

The first line of main (cli -a foo -b) doesn't explode, but the second line does.

Expected Behaviour

The first line should explode as well.

Additional Context

I think this is another manifestation of #1546 (comment)

Debug Output

No response

@abesto abesto added the C-bug Category: Updating dependencies label Feb 1, 2024
@epage
Copy link
Member

epage commented Feb 1, 2024

Since this is a larger issue than the original title, I've renamed #1546 so we can track all of this in one place and closing in favor of that.

@epage epage closed this as not planned Won't fix, can't repro, duplicate, stale Feb 1, 2024
@abesto
Copy link
Author

abesto commented Feb 1, 2024

Yep, that makes sense. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: Updating dependencies
Projects
None yet
Development

No branches or pull requests

2 participants