diff options
author | Thomas Quillan <tjquillan@gmail.com> | 2022-12-04 13:49:21 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-12-04 13:49:21 -0500 |
commit | 5cef3872999f1084cb13013b002a6421c4aa3f15 (patch) | |
tree | c5a5ed26e1cd15105c2baddc1006f00bc257f6e1 | |
parent | 62513efc1bb87525213661d746ab9b8ebac4a60b (diff) |
Address deprecated clap features (#1251)
* Address deprecated clap features
* Move to Arg::get_id from Arg::get_name
* Move to ArgMatches::value_source
* Run rustfmt
-rw-r--r-- | src/cli.rs | 35 | ||||
-rw-r--r-- | src/config.rs | 3 |
2 files changed, 18 insertions, 20 deletions
@@ -3,7 +3,7 @@ use std::ffi::OsString; use std::path::PathBuf; use bat::assets::HighlightingAssets; -use clap::{AppSettings, ColorChoice, FromArgMatches, IntoApp, Parser}; +use clap::{AppSettings, ColorChoice, CommandFactory, FromArgMatches, Parser}; use lazy_static::lazy_static; use syntect::highlighting::Theme as SyntaxTheme; use syntect::parsing::SyntaxSet; @@ -1065,13 +1065,13 @@ pub struct Opt { /// Deprecated: use --true-color. pub _24_bit_color: Option<String>, - #[clap(parse(from_os_str))] + #[clap(value_parser)] /// First file to be compared when delta is being used in diff mode /// /// `delta file_1 file_2` is equivalent to `diff -u file_1 file_2 | delta`. pub minus_file: Option<PathBuf>, - #[clap(parse(from_os_str))] + #[clap(value_parser)] /// Second file to be compared when delta is being used in diff mode. pub plus_file: Option<PathBuf>, @@ -1138,7 +1138,7 @@ impl Opt { git_config: Option<GitConfig>, assets: HighlightingAssets, ) -> Self { - Self::from_clap_and_git_config(env, Self::into_app().get_matches(), git_config, assets) + Self::from_clap_and_git_config(env, Self::command().get_matches(), git_config, assets) } pub fn from_iter_and_git_config<I>( @@ -1153,7 +1153,7 @@ impl Opt { let assets = utils::bat::assets::load_highlighting_assets(); Self::from_clap_and_git_config( env, - Self::into_app().get_matches_from(iter), + Self::command().get_matches_from(iter), git_config, assets, ) @@ -1174,21 +1174,18 @@ impl Opt { } pub fn get_argument_and_option_names<'a>() -> HashMap<&'a str, &'a str> { - itertools::chain( - Self::into_app().get_opts(), - Self::into_app().get_arguments(), - ) - .filter_map(|arg| match (arg.get_name(), arg.get_long()) { - (name, Some(long)) => { - if IGNORED_OPTION_NAMES.contains(name) { - None - } else { - Some((name, long)) + itertools::chain(Self::command().get_opts(), Self::command().get_arguments()) + .filter_map(|arg| match (arg.get_id(), arg.get_long()) { + (name, Some(long)) => { + if IGNORED_OPTION_NAMES.contains(name) { + None + } else { + Some((name, long)) + } } - } - _ => None, - }) - .collect() + _ => None, + }) + .collect() } } diff --git a/src/config.rs b/src/config.rs index 4da616a7..24e26a47 100644 --- a/src/config.rs +++ b/src/config.rs @@ -1,6 +1,7 @@ use std::collections::HashMap; use std::path::PathBuf; +use clap::ValueSource; use regex::Regex; use syntect::highlighting::Style as SyntectStyle; use syntect::highlighting::Theme as SyntaxTheme; @@ -384,7 +385,7 @@ fn make_blame_palette(blame_palette: Option<String>, is_light_mode: bool) -> Vec /// Did the user supply `option` on the command line? pub fn user_supplied_option(option: &str, arg_matches: &clap::ArgMatches) -> bool { - arg_matches.occurrences_of(option) > 0 + arg_matches.value_source(option) == Some(ValueSource::CommandLine) } pub fn delta_unreachable(message: &str) -> ! { |