summaryrefslogtreecommitdiffstats
path: root/src/cli.rs
diff options
context:
space:
mode:
authorDan Davison <dandavison7@gmail.com>2020-07-15 10:53:49 -0400
committerDan Davison <dandavison7@gmail.com>2020-07-15 15:36:31 -0400
commitb888c03610a008d2c3f441476eeb2a3104397089 (patch)
tree6f9ba949adfade5f0cb88427f4c018905360cd4e /src/cli.rs
parent5c9286d976ec96a887a3178857535949a2b6647a (diff)
Fix programmatic construction of option/flag names
Fixes #253
Diffstat (limited to 'src/cli.rs')
-rw-r--r--src/cli.rs44
1 files changed, 26 insertions, 18 deletions
diff --git a/src/cli.rs b/src/cli.rs
index 1df0202b..52a53d24 100644
--- a/src/cli.rs
+++ b/src/cli.rs
@@ -1,4 +1,4 @@
-use std::collections::HashSet;
+use std::collections::{HashMap, HashSet};
#[cfg(test)]
use std::ffi::OsString;
use std::path::PathBuf;
@@ -580,13 +580,21 @@ impl Opt {
}
#[allow(dead_code)]
- pub fn get_option_or_flag_names<'a>() -> HashSet<&'a str> {
- let names: HashSet<&str> = itertools::chain(
- Self::clap().p.opts.iter().filter_map(|opt| opt.s.long),
- Self::clap().p.flags.iter().filter_map(|opt| opt.s.long),
+ pub fn get_option_names<'a>() -> HashMap<&'a str, &'a str> {
+ itertools::chain(
+ Self::clap()
+ .p
+ .opts
+ .iter()
+ .map(|opt| (opt.b.name, opt.s.long.unwrap())),
+ Self::clap()
+ .p
+ .flags
+ .iter()
+ .map(|opt| (opt.b.name, opt.s.long.unwrap())),
)
- .collect();
- &names - &*IGNORED_OPTION_OR_FLAG_NAMES
+ .filter(|(name, _)| !IGNORED_OPTION_NAMES.contains(name))
+ .collect()
}
}
@@ -594,21 +602,21 @@ impl Opt {
// (1) Deprecated options
// (2) Pseudo-flag commands such as --list-languages
lazy_static! {
- static ref IGNORED_OPTION_OR_FLAG_NAMES: HashSet<&'static str> = vec![
- "commit-color",
- "file-color",
- "highlight-removed",
- "hunk-color",
- "hunk-style",
+ static ref IGNORED_OPTION_NAMES: HashSet<&'static str> = vec![
+ "deprecated-file-color",
+ "deprecated-hunk-style",
+ "deprecated-minus-background-color",
+ "deprecated-minus-emph-background-color",
+ "deprecated-hunk-color",
+ "deprecated-plus-emph-background-color",
+ "deprecated-plus-background-color",
+ "deprecated-highlight-minus-lines",
+ "deprecated-theme",
+ "deprecated-commit-color",
"list-languages",
"list-syntax-themes",
- "minus-color",
- "minus-emph-color",
- "plus-color",
- "plus-emph-color",
"show-config",
"show-syntax-themes",
- "theme",
]
.into_iter()
.collect();