style: change code style
This commit is contained in:
@@ -4,13 +4,6 @@ use std::{ env, fs, process };
|
|||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use std::os::unix::fs::PermissionsExt;
|
use std::os::unix::fs::PermissionsExt;
|
||||||
|
|
||||||
const RED: &str = "\x1B[91m";
|
|
||||||
const GREEN: &str = "\x1B[92m";
|
|
||||||
const YELLOW: &str = "\x1B[93m";
|
|
||||||
const BOLD: &str = "\x1B[1m";
|
|
||||||
const UNDER: &str = "\x1B[4m";
|
|
||||||
const END: &str = "\x1B[0m";
|
|
||||||
|
|
||||||
const DEFAULT_COMMIT_MSG_REGEXP: &str = "^(feat|fix|docs|style|refactor|test|chore)(\\([\\w\\-_.]+\\))?:\\s*.*";
|
const DEFAULT_COMMIT_MSG_REGEXP: &str = "^(feat|fix|docs|style|refactor|test|chore)(\\([\\w\\-_.]+\\))?:\\s*.*";
|
||||||
|
|
||||||
/// Git commit message format check util
|
/// Git commit message format check util
|
||||||
@@ -88,30 +81,6 @@ or mirror: {u}https://hatter.ink/wiki/view_raw.action?__access_token=PUBLIC&id=4
|
|||||||
"#, b = BOLD, e = END, u = UNDER));
|
"#, b = BOLD, e = END, u = UNDER));
|
||||||
}
|
}
|
||||||
|
|
||||||
fn search_git_root_path() -> Option<PathBuf> {
|
|
||||||
let mut p = PathBuf::from(".").canonicalize().unwrap_or_else(|e|
|
|
||||||
exit_with_error_message(&format!("Get current dir failed: {}", e))
|
|
||||||
);
|
|
||||||
loop {
|
|
||||||
if is_verbose() { print_info(&format!("Check git path: {:?}", p)); }
|
|
||||||
if p.join(".git").is_dir() {
|
|
||||||
if is_verbose() { print_ok(&format!("Found git path: {:?}", p)); }
|
|
||||||
return Some(p);
|
|
||||||
}
|
|
||||||
if !p.pop() { return None; }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn search_git_root_path_e() -> PathBuf {
|
|
||||||
search_git_root_path().unwrap_or_else(|| exit_with_error_message("Git root path not found!"))
|
|
||||||
}
|
|
||||||
|
|
||||||
fn get_home_e() -> PathBuf {
|
|
||||||
PathBuf::from(env::var("HOME").unwrap_or_else(|e|
|
|
||||||
exit_with_error_message(&format!("Get env HOME failed: {}!", e))
|
|
||||||
))
|
|
||||||
}
|
|
||||||
|
|
||||||
fn get_commit_msg_file(file: &str) -> Option<String> {
|
fn get_commit_msg_file(file: &str) -> Option<String> {
|
||||||
let settings_regexp = search_git_root_path_e().join("settings").join(file);
|
let settings_regexp = search_git_root_path_e().join("settings").join(file);
|
||||||
if is_verbose() { print_info(&format!("Check file: {:?}, exists: {}", settings_regexp, settings_regexp.exists())); }
|
if is_verbose() { print_info(&format!("Check file: {:?}, exists: {}", settings_regexp, settings_regexp.exists())); }
|
||||||
@@ -182,7 +151,36 @@ fn install_commit_msg(force: bool) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
fn is_verbose() -> bool { if let Ok(v) = env::var("VERBOSE") { v == "1" } else { false } }
|
fn search_git_root_path() -> Option<PathBuf> {
|
||||||
|
let mut p = PathBuf::from(".").canonicalize().unwrap_or_else(|e|
|
||||||
|
exit_with_error_message(&format!("Get current dir failed: {}", e))
|
||||||
|
);
|
||||||
|
loop {
|
||||||
|
if is_verbose() { print_info(&format!("Check git path: {:?}", p)); }
|
||||||
|
if p.join(".git").is_dir() {
|
||||||
|
if is_verbose() { print_ok(&format!("Found git path: {:?}", p)); }
|
||||||
|
return Some(p);
|
||||||
|
}
|
||||||
|
if !p.pop() { return None; }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn search_git_root_path_e() -> PathBuf {
|
||||||
|
search_git_root_path().unwrap_or_else(|| exit_with_error_message("Git root path not found!"))
|
||||||
|
}
|
||||||
|
|
||||||
|
const RED: &str = "\x1B[91m";
|
||||||
|
const GREEN: &str = "\x1B[92m";
|
||||||
|
const YELLOW: &str = "\x1B[93m";
|
||||||
|
const BOLD: &str = "\x1B[1m";
|
||||||
|
const UNDER: &str = "\x1B[4m";
|
||||||
|
const END: &str = "\x1B[0m";
|
||||||
|
|
||||||
|
fn get_home_e() -> PathBuf {
|
||||||
|
PathBuf::from(std::env::var("HOME").unwrap_or_else(|e| exit_with_error_message(&format!("Get env HOME failed: {}!", e))))
|
||||||
|
}
|
||||||
|
|
||||||
|
fn is_verbose() -> bool { if let Ok(v) = std::env::var("VERBOSE") { v == "1" } else { false } }
|
||||||
|
|
||||||
fn exit_with_error() -> ! { process::exit(1) }
|
fn exit_with_error() -> ! { process::exit(1) }
|
||||||
fn exit_with_error_message(msg: &str) -> ! { print_error(msg); exit_with_error() }
|
fn exit_with_error_message(msg: &str) -> ! { print_error(msg); exit_with_error() }
|
||||||
|
|||||||
Reference in New Issue
Block a user