refactor: add command en_us()

This commit is contained in:
2020-07-26 11:31:37 +08:00
parent 40ae1ea14e
commit 08aa838c80

View File

@@ -1,6 +1,16 @@
use std::path::PathBuf; use std::path::PathBuf;
use std::process::Command; 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<PathBuf> { pub fn get_git_base_path() -> Option<PathBuf> {
match PathBuf::from(".").canonicalize() { match PathBuf::from(".").canonicalize() {
Err(e) => { Err(e) => {
@@ -21,7 +31,7 @@ pub fn get_git_base_path() -> Option<PathBuf> {
pub fn check_git_status() -> bool { pub fn check_git_status() -> bool {
trace!("Run: git fetch --dry-run"); 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) => { Err(e) => {
warn!("Error in run git fetch --dry-run: {}", e); warn!("Error in run git fetch --dry-run: {}", e);
return false; return false;
@@ -38,7 +48,7 @@ pub fn check_git_status() -> bool {
}, },
} }
trace!("Run: git status"); 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) => { Err(e) => {
warn!("Error in run git status: {}", e); warn!("Error in run git status: {}", e);
return false; return false;
@@ -62,7 +72,7 @@ pub fn check_git_status() -> bool {
pub fn get_git_hash() -> Option<String> { pub fn get_git_hash() -> Option<String> {
trace!("Run: git rev-parse HEAD"); 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) => { Err(e) => {
warn!("Error in run git rev-parse HEAD: {}", e); warn!("Error in run git rev-parse HEAD: {}", e);
None None