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

Arguments with default values conflict even if not used #1605

Closed
0ndorio opened this issue Dec 9, 2019 · 2 comments · Fixed by #1869
Closed

Arguments with default values conflict even if not used #1605

0ndorio opened this issue Dec 9, 2019 · 2 comments · Fixed by #1869
Labels
C-bug Category: Updating dependencies
Milestone

Comments

@0ndorio
Copy link
Contributor

0ndorio commented Dec 9, 2019

Attention: This is directly related to #1071

The original issue was already marked as fixed but it seems like the bug was not fully eliminated.


Rust Version

  • rustc 1.39.0 (4560ea788 2019-11-04)

Affected Version of clap

Expected Behavior Summary

I expect conflicts to happen only when conflicting arguments are explicitly present on the command line.

Actual Behavior Summary

As mentioned in #1071 originally it was enough for an argument to have a default_value configured to cause a conflict. This was fixed with 58b5b4b but it seems like the fix only applied to cases where defaults and conflicts_with are present on different arguments. As conflicts_with automatically applies to both related arguments it is also possible to apply the option the argument with the default option.

This again triggers the same error message as the original issue.

Sample Code or Link to Sample Code

use clap::{App, Arg}; // 2.33.0

fn main() {
    let result = App::new("conflict")
        .arg(Arg::from_usage("-o, --opt=[opt] 'some opt'")
            .default_value("default")
            .conflicts_with("flag"))
        .arg(Arg::from_usage("-f, --flag 'some flag'")
            .conflicts_with("opt"))
        .get_matches_from_safe(vec!["myprog", "-f"]);
        
    eprintln!("{:#?}", result);
    
    assert!(result.is_ok());
    let m = result.unwrap();
    
    assert_eq!(m.value_of("opt"), Some("default"));
    assert!(m.is_present("flag"));
}

https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=9913e0f7a7905f7be0131ae53ef4ec63

@svenfoo
Copy link

svenfoo commented Nov 5, 2020

If I understand the history of this ticket correctly, the bug is still present in the latest stable release, which is 2.33.3 at this point, and fixed in 3.0, which is still in beta at this point, right?

Just asking because it seems that I just ran into it using clap 2.33.3.

@pksunkara
Copy link
Member

Yes.

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

Successfully merging a pull request may close this issue.

4 participants