From 50bb924ee30582cfc8456f018f0853c6af4537ec Mon Sep 17 00:00:00 2001 From: Ed Page Date: Thu, 1 Sep 2022 20:35:49 -0500 Subject: [PATCH] refactor: Replace multiple_occurrences --- src/bin/bat/app.rs | 4 ++-- src/bin/bat/clap_app.rs | 15 ++++++++------- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/bin/bat/app.rs b/src/bin/bat/app.rs index 87387782..f9f0044f 100644 --- a/src/bin/bat/app.rs +++ b/src/bin/bat/app.rs @@ -84,7 +84,7 @@ impl App { Some("never") => PagingMode::Never, Some("auto") | None => { // If we have -pp as an option when in auto mode, the pager should be disabled. - let extra_plain = self.matches.occurrences_of("plain") > 1; + let extra_plain = self.matches.get_count("plain") > 1; if extra_plain || self.matches.is_present("no-paging") { PagingMode::Never } else if inputs.iter().any(Input::is_stdin) { @@ -297,7 +297,7 @@ impl App { HashSet::new() } else if matches.is_present("number") { [StyleComponent::LineNumbers].iter().cloned().collect() - } else if matches.is_present("plain") { + } else if 0 < matches.get_count("plain") { [StyleComponent::Plain].iter().cloned().collect() } else { let env_style_components: Option> = env::var("BAT_STYLE") diff --git a/src/bin/bat/clap_app.rs b/src/bin/bat/clap_app.rs index 5297cfb4..dfbf4435 100644 --- a/src/bin/bat/clap_app.rs +++ b/src/bin/bat/clap_app.rs @@ -1,5 +1,6 @@ use clap::{ - crate_name, crate_version, value_parser, AppSettings, Arg, ArgGroup, ColorChoice, Command, + crate_name, crate_version, value_parser, AppSettings, Arg, ArgAction, ArgGroup, ColorChoice, + Command, }; use once_cell::sync::Lazy; use std::env; @@ -73,7 +74,7 @@ pub fn build_app(interactive_output: bool) -> Command<'static> { .overrides_with("number") .short('p') .long("plain") - .multiple_occurrences(true) + .action(ArgAction::Count) .help("Show plain style (alias for '--style=plain').") .long_help( "Only show plain style, no decorations. This is an alias for \ @@ -100,7 +101,7 @@ pub fn build_app(interactive_output: bool) -> Command<'static> { .long("highlight-line") .short('H') .takes_value(true) - .multiple_occurrences(true) + .action(ArgAction::Append) .value_name("N:M") .help("Highlight lines N through M.") .long_help( @@ -117,7 +118,7 @@ pub fn build_app(interactive_output: bool) -> Command<'static> { Arg::new("file-name") .long("file-name") .takes_value(true) - .multiple_occurrences(true) + .action(ArgAction::Append) .value_name("name") .value_parser(value_parser!(PathBuf)) .help("Specify the name to display for a file.") @@ -337,7 +338,7 @@ pub fn build_app(interactive_output: bool) -> Command<'static> { Arg::new("map-syntax") .short('m') .long("map-syntax") - .multiple_occurrences(true) + .action(ArgAction::Append) .takes_value(true) .value_name("glob:syntax") .help("Use the specified syntax for files matching the glob pattern ('*.cpp:C++').") @@ -352,7 +353,7 @@ pub fn build_app(interactive_output: bool) -> Command<'static> { ) .arg( Arg::new("ignored-suffix") - .multiple_occurrences(true) + .action(ArgAction::Append) .takes_value(true) .long("ignored-suffix") .hide_short_help(true) @@ -450,7 +451,7 @@ pub fn build_app(interactive_output: bool) -> Command<'static> { Arg::new("line-range") .long("line-range") .short('r') - .multiple_occurrences(true) + .action(ArgAction::Append) .takes_value(true) .value_name("N:M") .help("Only print the lines from N to M.")