diff options
| author | Paolo Insogna <paolo@cowtech.it> | 2023-03-05 23:32:11 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-03-05 17:32:11 -0500 |
| commit | 3a09926e4576542e4fac04943dc6781eb026656e (patch) | |
| tree | 33ebceccf36f3a772d084028b834839166f2deb7 /src/cli.rs | |
| parent | 5e4faabfd36b3fae69dc15b2f39f18196bd5154c (diff) | |
Added config option. (#1324)
* feat: Added config option.
Diffstat (limited to 'src/cli.rs')
| -rw-r--r-- | src/cli.rs | 32 |
1 files changed, 31 insertions, 1 deletions
@@ -55,6 +55,23 @@ A feature name may not contain whitespace. You can activate multiple features: If more than one feature sets the same option, the last one wins. +If an option is present in the [delta] section, then features are not considered at all. + +If you want an option to be fully overridable by a feature and also have a non default value when +no features are used, then you need to define a \"default\" feature and include it in the main +delta configuration. + +For instance: + +[delta] +feature = default-feature + +[delta \"default-feature\"] +width = 123 + +At this point, you can override features set in the command line or in the environment variables +and the \"last one wins\" rules will apply as expected. + STYLES ------ @@ -276,6 +293,10 @@ pub struct Opt { /// intended for other tools that use delta. pub color_only: bool, + #[arg(long = "config", default_value = "", value_name = "PATH")] + /// Load the config file at PATH instead of ~/.gitconfig. + pub config: String, + #[arg( long = "commit-decoration-style", default_value = "", @@ -1135,7 +1156,16 @@ impl Opt { git_config: Option<GitConfig>, assets: HighlightingAssets, ) -> Self { - Self::from_clap_and_git_config(env, Self::command().get_matches(), git_config, assets) + let mut final_config = git_config; + let matches = Self::command().get_matches(); + + if let Some(path) = matches.get_one::<String>("config") { + if !path.is_empty() { + final_config = Some(GitConfig::try_create_from_path(&env, path)); + } + } + + Self::from_clap_and_git_config(env, matches, final_config, assets) } pub fn from_iter_and_git_config<I>( |
