From 08aa838c8020e55b4c5eae695de8609473cef908 Mon Sep 17 00:00:00 2001 From: "Hatter Jiang@Pixelbook" Date: Sun, 26 Jul 2020 11:31:37 +0800 Subject: [PATCH] refactor: add command en_us() --- src/git.rs | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/git.rs b/src/git.rs index e43f17c..f66b230 100644 --- a/src/git.rs +++ b/src/git.rs @@ -1,6 +1,16 @@ use std::path::PathBuf; use std::process::Command; +trait RunCommandAsEnUs { + fn en_us(&mut self) -> &mut Self; +} + +impl RunCommandAsEnUs for Command { + fn en_us(&mut self) -> &mut Self { + self.env("LANG", "en_US") + } +} + pub fn get_git_base_path() -> Option { match PathBuf::from(".").canonicalize() { Err(e) => { @@ -21,7 +31,7 @@ pub fn get_git_base_path() -> Option { pub fn check_git_status() -> bool { trace!("Run: git fetch --dry-run"); - match Command::new("git").env("LANG", "en_US").args(&["fetch", "--dry-run"]).output() { + match Command::new("git").en_us().args(&["fetch", "--dry-run"]).output() { Err(e) => { warn!("Error in run git fetch --dry-run: {}", e); return false; @@ -38,7 +48,7 @@ pub fn check_git_status() -> bool { }, } trace!("Run: git status"); - match Command::new("git").env("LANG", "en_US").args(&["status"]).output() { + match Command::new("git").en_us().args(&["status"]).output() { Err(e) => { warn!("Error in run git status: {}", e); return false; @@ -62,7 +72,7 @@ pub fn check_git_status() -> bool { pub fn get_git_hash() -> Option { trace!("Run: git rev-parse HEAD"); - match Command::new("git").args(&["rev-parse", "HEAD"]).output(){ + match Command::new("git").en_us().args(&["rev-parse", "HEAD"]).output(){ Err(e) => { warn!("Error in run git rev-parse HEAD: {}", e); None