feat(git): adding the EZA_OVERRIDE_GIT env var

This var will override any --git or --git-repos
This commit is contained in:
Martin Fillon 2023-10-10 11:17:39 +02:00 committed by MartinFillon
parent 143f37a7eb
commit bad3f1a615
No known key found for this signature in database
GPG key ID: 16DC898F53F94853
3 changed files with 19 additions and 5 deletions

View file

@ -274,6 +274,10 @@ Specifies the colour scheme used to highlight files based on their name and kind
For more information on the format of these environment variables, see the [eza_colors.5.md](eza_colors.5.md) manual page.
## `EZA_OVERRIDE_GIT`
Overrides any `--git` or `--git-repos` argument
EXIT STATUSES
=============

View file

@ -52,6 +52,9 @@ pub static EZA_GRID_ROWS: &str = "EZA_GRID_ROWS";
pub static EXA_ICON_SPACING: &str = "EXA_ICON_SPACING";
pub static EZA_ICON_SPACING: &str = "EZA_ICON_SPACING";
pub static EXA_OVERRIDE_GIT: &str = "EXA_OVERRIDE_GIT";
pub static EZA_OVERRIDE_GIT: &str = "EZA_OVERRIDE_GIT";
/// Mockable wrapper for `std::env::var_os`.
pub trait Vars {
fn get(&self, name: &'static str) -> Option<OsString>;

View file

@ -231,7 +231,7 @@ impl TableOptions {
let time_format = TimeFormat::deduce(matches, vars)?;
let size_format = SizeFormat::deduce(matches)?;
let user_format = UserFormat::deduce(matches)?;
let columns = Columns::deduce(matches)?;
let columns = Columns::deduce(matches, vars)?;
Ok(Self {
size_format,
time_format,
@ -242,14 +242,21 @@ impl TableOptions {
}
impl Columns {
fn deduce(matches: &MatchedFlags<'_>) -> Result<Self, OptionsError> {
fn deduce<V: Vars>(matches: &MatchedFlags<'_>, vars: &V) -> Result<Self, OptionsError> {
use crate::options::vars;
let time_types = TimeTypes::deduce(matches)?;
let git = matches.has(&flags::GIT)? && !matches.has(&flags::NO_GIT)?;
let subdir_git_repos = matches.has(&flags::GIT_REPOS)? && !matches.has(&flags::NO_GIT)?;
let no_git_env = vars
.get_with_fallback(vars::EXA_OVERRIDE_GIT, vars::EZA_OVERRIDE_GIT)
.is_some();
let git = matches.has(&flags::GIT)? && !matches.has(&flags::NO_GIT)? && !no_git_env;
let subdir_git_repos =
matches.has(&flags::GIT_REPOS)? && !matches.has(&flags::NO_GIT)? && !no_git_env;
let subdir_git_repos_no_stat = !subdir_git_repos
&& matches.has(&flags::GIT_REPOS_NO_STAT)?
&& !matches.has(&flags::NO_GIT)?;
&& !matches.has(&flags::NO_GIT)?
&& !no_git_env;
let blocksize = matches.has(&flags::BLOCKSIZE)?;
let group = matches.has(&flags::GROUP)?;