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

Conflicts don't propagate from the global level to the subcommand #1204

Open
larsrh opened this issue Mar 6, 2018 · 2 comments
Open

Conflicts don't propagate from the global level to the subcommand #1204

larsrh opened this issue Mar 6, 2018 · 2 comments
Labels
A-parsing Area: Parser's logic and needs it changed somehow. A-validators Area: ArgMatches validation logi C-bug Category: Updating dependencies E-medium Call for participation: Experience needed to fix: Medium / intermediate

Comments

@larsrh
Copy link

larsrh commented Mar 6, 2018

As discussed on Gitter: https://gitter.im/kbknapp/clap-rs?at=5a9f003af3f6d24c68450335

Affected Version of clap

2.31.1

Expected Behavior Summary

When declaring that a subcommand argument is in conflict with a global argument, clap should produce an error no matter whether the global argument comes after or before the subcommand.

Actual Behavior Summary

global argument comes after: conflict
global argument comes before: no conflict

Sample Code or Link to Sample Code

(by @kbknapp)

extern crate clap;
use clap::{Arg, App, SubCommand};

fn main(){
    let _ = App::new("fake")
        .arg(Arg::with_name("glob")
            .short("g")
            .global(true))
        .subcommand(SubCommand::with_name("foo")
            .arg(Arg::with_name("conf")
                .short("c")
                .conflicts_with("glob")))
        .get_matches_from(vec!["fake", "foo", "-g", "-c"]);
}

Steps to Reproduce the issue

Run the above code with fake foo -g -c and fake -g foo -c and observe the difference.

@kbknapp kbknapp added C-bug Category: Updating dependencies P3: want to have A-parsing Area: Parser's logic and needs it changed somehow. labels Mar 7, 2018
@kbknapp
Copy link
Member

kbknapp commented Mar 7, 2018

Thanks for submitting!

For my own notes and from the gitter chat

  • The flag is actually propagated down to the subcommand correctly, but the conflict doesn't register
  • The same happens if we use options instead of flags (so it's not flag specific)

@mainrs
Copy link

mainrs commented Aug 25, 2018

Just a side note, shouldn't the help also not display the global arg if the subcommand arg is in conflict and the subcommand arg is required? This case wouldn't allow the global arg anyway to be passed down.

extern crate clap;
use clap::{Arg, App, SubCommand};

fn main() {
	let _ = App::new("fake")
		.arg(Arg::with_name("glob")
			.short("g")
			.global(true))
		.subcommand(SubCommand::with_name("foo")
			.arg(Arg::with_name("conf")
				.short("c")
				.takes_value(true)
				.required(true)
				.conflicts_with("glob")))
		.get_matches_from(vec!["fake", "foo", "-g", "-c"]);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-parsing Area: Parser's logic and needs it changed somehow. A-validators Area: ArgMatches validation logi C-bug Category: Updating dependencies E-medium Call for participation: Experience needed to fix: Medium / intermediate
Projects
None yet
Development

No branches or pull requests

6 participants