ripgrep 12.1.1
+SIMD -AVX (compiled)
-SIMD -AVX (runtime)
RUSTFLAGS="-C target-cpu=native" cargo +nightly install ripgrep --features 'simd-accel'
$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 16.04.7 LTS
Release: 16.04
Codename: xenial
ripgrep exits with the following error...
error: The argument '--pretty' was provided more than once, but cannot be used multiple times
...if -p or --pretty is in the configuration file and condensed short option syntax is used on the command line.
RIPGREP_CONFIG_PATH and a configuration file containing -p or --prettyripgrep with -p -z or --pretty -z at the command line.ripgrep with -p -z -p at the command linealias-compatible way as it should.ripgrep with -pz at the command line.$ rg -pz foo /usr/share/doc
error: The argument '--pretty' was provided more than once, but cannot be used multiple times
USAGE:
rg [OPTIONS] PATTERN [PATH ...]
rg [OPTIONS] [-e PATTERN ...] [-f PATTERNFILE ...] [PATH ...]
rg [OPTIONS] --files [PATH ...]
rg [OPTIONS] --type-list
command | rg [OPTIONS] PATTERN
For more information try --help
It shouldn't matter what form it takes.
-pz should behave identically to -p -z.
I think the config file is a red herring. I get the same issue with just the command line. The option-stacking thing does seem relevant though
These fail:
% RIPGREP_CONFIG_PATH= \rg -p -pz x <<< xyz
% RIPGREP_CONFIG_PATH= \rg -ppz x <<< xyz
But these are OK:
% RIPGREP_CONFIG_PATH= \rg -pz -p x <<< xyz
% RIPGREP_CONFIG_PATH= \rg -pzp x <<< xyz
% RIPGREP_CONFIG_PATH= \rg -zpp x <<< xyz
% RIPGREP_CONFIG_PATH= \rg -pp -z x <<< xyz
% RIPGREP_CONFIG_PATH= \rg -p -p -z x <<< xyz
It does it with all other options i tried, too, not just --pretty. I assume it's a Clap bug...?
Yeah, i think so, since fd also does it:
% fd -1 -pp -L README
README.md
% fd -1 -ppL README
error: The argument '--full-path' was provided more than once, but cannot be used multiple times ...
I couldn't find a related issue in the clap repo, i guess it needs reported there
OK. I'll try to find time to put together a minimal reproducer tomorrow.
EDIT: The day didn't go well. Tomorrow maybe.
I've tried to put together a reproducer, but I can't remember what the proper way is to ask clap for that alias-compatible behaviour where you can specify an argument multiple times but the additional copies have no semantic significance within the program.
@ssokolow Thanks for looking into this! I believe the setting you're looking for is clap::AppSettings::AllArgsOverrideSelf. ripgrep sets it here.
Thanks. I've now got a reproducer:
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),
}
}
}
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'm not feeling motivated to open a bug right now but I'll do it later if someone else doesn't beat me to it. (It's near the end of my day and anything which introduces a new social component feels tiring.)
Reported as clap-rs/clap#2171
Most helpful comment
Thanks. I've now got a reproducer:
I'm not feeling motivated to open a bug right now but I'll do it later if someone else doesn't beat me to it. (It's near the end of my day and anything which introduces a new social component feels tiring.)