Use overrides_with to clean up opposing arg logic

This commit is contained in:
Vukašin Stepanović 2021-08-23 15:44:11 +02:00
parent 8da936abd8
commit 3ebd78cf02
2 changed files with 18 additions and 21 deletions

View File

@ -32,7 +32,7 @@ pub fn build_app() -> App<'static, 'static> {
.arg( .arg(
Arg::with_name("no-hidden") Arg::with_name("no-hidden")
.long("no-hidden") .long("no-hidden")
.overrides_with("no-hidden") .overrides_with("hidden")
.hidden(true) .hidden(true)
.long_help( .long_help(
"Overrides --hidden.", "Overrides --hidden.",
@ -53,7 +53,7 @@ pub fn build_app() -> App<'static, 'static> {
.arg( .arg(
Arg::with_name("ignore") Arg::with_name("ignore")
.long("ignore") .long("ignore")
.overrides_with("ignore") .overrides_with("no-ignore")
.hidden(true) .hidden(true)
.long_help( .long_help(
"Overrides --no-ignore.", "Overrides --no-ignore.",
@ -72,7 +72,7 @@ pub fn build_app() -> App<'static, 'static> {
.arg( .arg(
Arg::with_name("ignore-vcs") Arg::with_name("ignore-vcs")
.long("ignore-vcs") .long("ignore-vcs")
.overrides_with("ignore-vcs") .overrides_with("no-ignore-vcs")
.hidden(true) .hidden(true)
.long_help( .long_help(
"Overrides --no-ignore-vcs.", "Overrides --no-ignore-vcs.",
@ -88,6 +88,7 @@ pub fn build_app() -> App<'static, 'static> {
Arg::with_name("rg-alias-hidden-ignore") Arg::with_name("rg-alias-hidden-ignore")
.short("u") .short("u")
.long("unrestricted") .long("unrestricted")
.overrides_with_all(&["ignore", "no-hidden"])
.multiple(true) .multiple(true)
.hidden_short_help(true) .hidden_short_help(true)
.long_help( .long_help(
@ -165,7 +166,7 @@ pub fn build_app() -> App<'static, 'static> {
.arg( .arg(
Arg::with_name("relative-path") Arg::with_name("relative-path")
.long("relative-path") .long("relative-path")
.overrides_with("relative-path") .overrides_with("absolute-path")
.hidden(true) .hidden(true)
.long_help( .long_help(
"Overrides --absolute-path.", "Overrides --absolute-path.",
@ -200,7 +201,7 @@ pub fn build_app() -> App<'static, 'static> {
.arg( .arg(
Arg::with_name("no-follow") Arg::with_name("no-follow")
.long("no-follow") .long("no-follow")
.overrides_with("no-follow") .overrides_with("follow")
.hidden(true) .hidden(true)
.long_help( .long_help(
"Overrides --follow.", "Overrides --follow.",

View File

@ -116,7 +116,7 @@ fn run() -> Result<ExitCode> {
return Err(anyhow!("No valid search paths given.")); return Err(anyhow!("No valid search paths given."));
} }
if matches.is_present("absolute-path") && !matches.is_present("relative-path") { if matches.is_present("absolute-path") {
search_paths = search_paths search_paths = search_paths
.iter() .iter()
.map(|path_buffer| { .map(|path_buffer| {
@ -333,21 +333,17 @@ fn run() -> Result<ExitCode> {
let config = Options { let config = Options {
case_sensitive, case_sensitive,
search_full_path: matches.is_present("full-path"), search_full_path: matches.is_present("full-path"),
ignore_hidden: matches.is_present("no-hidden") ignore_hidden: !(matches.is_present("hidden")
|| !(matches.is_present("hidden") || matches.occurrences_of("rg-alias-hidden-ignore") >= 2),
|| matches.occurrences_of("rg-alias-hidden-ignore") >= 2), read_fdignore: !(matches.is_present("no-ignore")
read_fdignore: matches.is_present("ignore") || matches.is_present("rg-alias-hidden-ignore")),
|| !(matches.is_present("no-ignore") || matches.is_present("rg-alias-hidden-ignore")), read_vcsignore: !(matches.is_present("no-ignore")
read_vcsignore: matches.is_present("ignore") || matches.is_present("ignore-vcs") || { || matches.is_present("rg-alias-hidden-ignore")
!(matches.is_present("no-ignore") || matches.is_present("no-ignore-vcs")),
|| matches.is_present("rg-alias-hidden-ignore") read_global_ignore: !(matches.is_present("no-ignore")
|| matches.is_present("no-ignore-vcs")) || matches.is_present("rg-alias-hidden-ignore")
}, || matches.is_present("no-global-ignore-file")),
read_global_ignore: matches.is_present("ignore") follow_links: matches.is_present("follow"),
|| !(matches.is_present("no-ignore")
|| matches.is_present("rg-alias-hidden-ignore")
|| matches.is_present("no-global-ignore-file")),
follow_links: matches.is_present("follow") && !matches.is_present("no-follow"),
one_file_system: matches.is_present("one-file-system"), one_file_system: matches.is_present("one-file-system"),
null_separator: matches.is_present("null_separator"), null_separator: matches.is_present("null_separator"),
max_depth: matches max_depth: matches