diff options
author | Dan Davison <dandavison7@gmail.com> | 2020-06-15 10:41:54 -0400 |
---|---|---|
committer | Dan Davison <dandavison7@gmail.com> | 2020-06-21 16:54:23 -0400 |
commit | a7317e7772e6265c61ee5c57fc56e866aca3d103 (patch) | |
tree | d093709cd505233be3f2c424aecc3c07b52f243d | |
parent | c0fc406f5897b35497688d6d4821c3918fef2f4a (diff) |
Reimplement --color-only as a feature
-rw-r--r-- | src/features/color_only.rs | 60 | ||||
-rw-r--r-- | src/features/mod.rs | 5 | ||||
-rw-r--r-- | src/rewrite_options.rs | 15 | ||||
-rw-r--r-- | src/set_options.rs | 3 |
4 files changed, 68 insertions, 15 deletions
diff --git a/src/features/color_only.rs b/src/features/color_only.rs new file mode 100644 index 00000000..327111d6 --- /dev/null +++ b/src/features/color_only.rs @@ -0,0 +1,60 @@ +use crate::features::OptionValueFunction; + +pub fn make_feature() -> Vec<(String, OptionValueFunction)> { + builtin_feature!([ + ( + "color-only", + bool, + None, + _opt => true + ), + ( + "commit-decoration-style", + String, + None, + _opt => "none" + ), + ( + "commit-style", + String, + None, + _opt => "raw" + ), + ( + "file-decoration-style", + String, + None, + _opt => "none" + ), + ( + "file-style", + String, + None, + _opt => "raw" + ), + ( + "hunk-header-decoration-style", + String, + None, + _opt => "none" + ), + ( + "hunk-header-style", + String, + None, + _opt => "raw" + ), + ( + "keep-plus-minus-markers", + bool, + None, + _opt => true + ), + ( + "tabs", + usize, + None, + _opt => 0 + ) + ]) +} diff --git a/src/features/mod.rs b/src/features/mod.rs index 71d9879d..77520bb7 100644 --- a/src/features/mod.rs +++ b/src/features/mod.rs @@ -27,6 +27,10 @@ type OptionValueFunction = Box<dyn Fn(&cli::Opt, &Option<GitConfig>) -> Provenan pub fn make_builtin_features() -> HashMap<String, BuiltinFeature> { vec![ ( + "color-only".to_string(), + color_only::make_feature().into_iter().collect(), + ), + ( "diff-highlight".to_string(), diff_highlight::make_feature().into_iter().collect(), ), @@ -65,6 +69,7 @@ macro_rules! builtin_feature { } } +pub mod color_only; pub mod diff_highlight; pub mod diff_so_fancy; pub mod navigate; diff --git a/src/rewrite_options.rs b/src/rewrite_options.rs index 1ce4bc0c..a7919610 100644 --- a/src/rewrite_options.rs +++ b/src/rewrite_options.rs @@ -14,21 +14,6 @@ pub fn apply_rewrite_rules(opt: &mut cli::Opt, arg_matches: &clap::ArgMatches) { rewrite_options_to_implement_deprecated_commit_and_file_style_box_option(opt); rewrite_options_to_implement_deprecated_hunk_style_option(opt); rewrite_options_to_implement_deprecated_theme_option(opt, arg_matches); - rewrite_options_to_implement_color_only(opt); -} - -/// Implement --color-only -fn rewrite_options_to_implement_color_only(opt: &mut cli::Opt) { - if opt.color_only { - opt.keep_plus_minus_markers = true; - opt.tab_width = 0; - opt.commit_style = "raw".to_string(); - opt.commit_decoration_style = "none".to_string(); - opt.file_style = "raw".to_string(); - opt.file_decoration_style = "none".to_string(); - opt.hunk_header_style = "raw".to_string(); - opt.hunk_header_decoration_style = "none".to_string(); - } } /// Honor deprecated --theme diff --git a/src/set_options.rs b/src/set_options.rs index 3f0fdce8..10f0145c 100644 --- a/src/set_options.rs +++ b/src/set_options.rs @@ -23,6 +23,9 @@ pub fn set_options( git_config: &mut Option<git_config::GitConfig>, arg_matches: &clap::ArgMatches, ) { + if opt.color_only { + opt.features = format!("{} color-only", opt.features); + } // Handle options which default to an arbitrary git config value. // TODO: incorporate this logic into the set_options macro. if !config::user_supplied_option("whitespace-error-style", arg_matches) { |