Skip to content

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

@ssokolow

Description

@ssokolow

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    💸 $5A-parsingArea: Parser's logic and needs it changed somehow.C-bugCategory: bug

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions