Skip to content

Commit

Permalink
Address deprecated clap features (#1251)
Browse files Browse the repository at this point in the history
* Address deprecated clap features

* Move to Arg::get_id from Arg::get_name

* Move to ArgMatches::value_source

* Run rustfmt
  • Loading branch information
tjquillan authored Dec 4, 2022
1 parent 62513ef commit 5cef387
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 20 deletions.
35 changes: 16 additions & 19 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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>,

Expand Down Expand Up @@ -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>(
Expand All @@ -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,
)
Expand All @@ -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()
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/config.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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) -> ! {
Expand Down

0 comments on commit 5cef387

Please sign in to comment.