refactor: Replace multiple_occurrences

This commit is contained in:
Ed Page 2022-09-01 20:35:49 -05:00 committed by David Peter
parent e8e1c1d6c9
commit 50bb924ee3
2 changed files with 10 additions and 9 deletions

View File

@ -84,7 +84,7 @@ impl App {
Some("never") => PagingMode::Never, Some("never") => PagingMode::Never,
Some("auto") | None => { Some("auto") | None => {
// If we have -pp as an option when in auto mode, the pager should be disabled. // 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") { if extra_plain || self.matches.is_present("no-paging") {
PagingMode::Never PagingMode::Never
} else if inputs.iter().any(Input::is_stdin) { } else if inputs.iter().any(Input::is_stdin) {
@ -297,7 +297,7 @@ impl App {
HashSet::new() HashSet::new()
} else if matches.is_present("number") { } else if matches.is_present("number") {
[StyleComponent::LineNumbers].iter().cloned().collect() [StyleComponent::LineNumbers].iter().cloned().collect()
} else if matches.is_present("plain") { } else if 0 < matches.get_count("plain") {
[StyleComponent::Plain].iter().cloned().collect() [StyleComponent::Plain].iter().cloned().collect()
} else { } else {
let env_style_components: Option<Vec<StyleComponent>> = env::var("BAT_STYLE") let env_style_components: Option<Vec<StyleComponent>> = env::var("BAT_STYLE")

View File

@ -1,5 +1,6 @@
use clap::{ 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 once_cell::sync::Lazy;
use std::env; use std::env;
@ -73,7 +74,7 @@ pub fn build_app(interactive_output: bool) -> Command<'static> {
.overrides_with("number") .overrides_with("number")
.short('p') .short('p')
.long("plain") .long("plain")
.multiple_occurrences(true) .action(ArgAction::Count)
.help("Show plain style (alias for '--style=plain').") .help("Show plain style (alias for '--style=plain').")
.long_help( .long_help(
"Only show plain style, no decorations. This is an alias for \ "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") .long("highlight-line")
.short('H') .short('H')
.takes_value(true) .takes_value(true)
.multiple_occurrences(true) .action(ArgAction::Append)
.value_name("N:M") .value_name("N:M")
.help("Highlight lines N through M.") .help("Highlight lines N through M.")
.long_help( .long_help(
@ -117,7 +118,7 @@ pub fn build_app(interactive_output: bool) -> Command<'static> {
Arg::new("file-name") Arg::new("file-name")
.long("file-name") .long("file-name")
.takes_value(true) .takes_value(true)
.multiple_occurrences(true) .action(ArgAction::Append)
.value_name("name") .value_name("name")
.value_parser(value_parser!(PathBuf)) .value_parser(value_parser!(PathBuf))
.help("Specify the name to display for a file.") .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") Arg::new("map-syntax")
.short('m') .short('m')
.long("map-syntax") .long("map-syntax")
.multiple_occurrences(true) .action(ArgAction::Append)
.takes_value(true) .takes_value(true)
.value_name("glob:syntax") .value_name("glob:syntax")
.help("Use the specified syntax for files matching the glob pattern ('*.cpp:C++').") .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(
Arg::new("ignored-suffix") Arg::new("ignored-suffix")
.multiple_occurrences(true) .action(ArgAction::Append)
.takes_value(true) .takes_value(true)
.long("ignored-suffix") .long("ignored-suffix")
.hide_short_help(true) .hide_short_help(true)
@ -450,7 +451,7 @@ pub fn build_app(interactive_output: bool) -> Command<'static> {
Arg::new("line-range") Arg::new("line-range")
.long("line-range") .long("line-range")
.short('r') .short('r')
.multiple_occurrences(true) .action(ArgAction::Append)
.takes_value(true) .takes_value(true)
.value_name("N:M") .value_name("N:M")
.help("Only print the lines from N to M.") .help("Only print the lines from N to M.")