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

AllArgsOverrideSelf fails to take effect in certain patterns of arguments #2171

Closed
2 tasks done
ssokolow opened this issue Oct 13, 2020 · 4 comments · Fixed by #2297
Closed
2 tasks done

AllArgsOverrideSelf fails to take effect in certain patterns of arguments #2171

ssokolow opened this issue Oct 13, 2020 · 4 comments · Fixed by #2297
Labels
A-parsing Area: Parser's logic and needs it changed somehow. C-bug Category: Updating dependencies 💸 $5
Milestone

Comments

@ssokolow
Copy link

Make sure you completed the following tasks

Code

use clap::{Arg, App, AppSettings};

fn main() {
    let schema = App::new("ripgrep#1701 reproducer")
        .setting(AppSettings::AllArgsOverrideSelf)
        .arg(Arg::with_name("pretty")
            .short("p")
            .long("pretty"))
        .arg(Arg::with_name("search_zip")
            .short("z")
            .long("search-zip"));

    let test_args = &[
       vec!["reproducer", "-pz", "-p"],
       vec!["reproducer", "-pzp"],
       vec!["reproducer", "-zpp"],
       vec!["reproducer", "-pp", "-z"],
       vec!["reproducer", "-p", "-p", "-z"],

       vec!["reproducer", "-p", "-pz"],
       vec!["reproducer", "-ppz"],
    ];


    for argv in test_args {
        let matches = schema.clone().get_matches_from_safe(argv);
        match matches {
            Ok(_) => println!(" OK: {:?}", argv),
            Err(e) => println!("ERR: {:?} ({:?})", argv, e.kind),
        }
    }
}

Steps to reproduce the issue

  1. Run cargo run for the reproducer script

Version

  • Rust: rustc 1.47.0 (18bf6b4f0 2020-10-07)
  • Clap: 2.33.3

Actual Behavior Summary

 OK: ["reproducer", "-pz", "-p"]
 OK: ["reproducer", "-pzp"]
 OK: ["reproducer", "-zpp"]
 OK: ["reproducer", "-pp", "-z"]
 OK: ["reproducer", "-p", "-p", "-z"]
ERR: ["reproducer", "-p", "-pz"] (UnexpectedMultipleUsage)
ERR: ["reproducer", "-ppz"] (UnexpectedMultipleUsage)

I tripped over this when a script that invoked rg -pz errored out because I had --pretty in my ripgrep configuration file.

Expected Behavior Summary

All of the strings in the reproducer should behave identically.

Additional context

debug.log

@ssokolow ssokolow added the C-bug Category: Updating dependencies label Oct 13, 2020
@pksunkara pksunkara added A-parsing Area: Parser's logic and needs it changed somehow. 💸 $5 labels Oct 13, 2020
@pksunkara pksunkara added this to the 3.0 milestone Oct 13, 2020
@pksunkara pksunkara modified the milestones: 3.0, 3.1 Oct 23, 2020
@ldm0
Copy link
Member

ldm0 commented Jan 27, 2021

Linked to #1374, should be fixed by #2297, add regress tests later.

@ldm0 ldm0 mentioned this issue Jan 27, 2021
@ldm0
Copy link
Member

ldm0 commented Jan 27, 2021

Done.

@BurntSushi
Copy link
Contributor

@ldm0 Did this make it into a clap 2.x release? Or is it only fixed in clap 3.x?

@pksunkara
Copy link
Member

Only in 3.x

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. C-bug Category: Updating dependencies 💸 $5
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants