From 55af07b4d47ec46e948c1578b3fcdeb45521fbc0 Mon Sep 17 00:00:00 2001 From: Hatter Jiang Date: Sun, 12 Jul 2020 00:42:34 +0800 Subject: [PATCH] feat: add usage for commit-msg --- scripts/commit-msg.crs | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/scripts/commit-msg.crs b/scripts/commit-msg.crs index f6b52d4..4e01af2 100755 --- a/scripts/commit-msg.crs +++ b/scripts/commit-msg.crs @@ -9,6 +9,10 @@ fn main() { exit_with_error_message("Commit message is EMPTY!"); }); + if arg1 == "usage" || arg1 == "USAGE" { + print_usage(); return; + } + let is_install = arg1 == "install" || arg1 == "INSTALL"; let is_force_install = arg1 == "forceinstall" || arg1 == "FORCEINSTALL" || arg1 == "force-install" || arg1 == "FORCE-INSTALL" @@ -28,9 +32,21 @@ fn main() { if is_commit_message_matches { print_ok("Commit message rule matches"); } else { - print_info(&format!(r#"Please follow the commit spec: -Format: (): - is optional + print_usage(); + exit_with_error_message("Commit message rule is NOT matched"); + } +} + +const RED: &str = "\x1B[91m"; +const GREEN: &str = "\x1B[92m"; +const BOLD: &str = "\x1B[1m"; +const UNDER: &str = "\x1B[4m"; +const END: &str = "\x1B[0m"; + +fn print_usage() { + print_info(&format!(r#"Please follow the commit spec: +Format: {}{}(){}: {} + is optional feat: add hat wobble ^--^ ^------------^ @@ -49,17 +65,9 @@ chore : updating grunt tasks etc; no production code change Reference: {}https://gist.github.com/joshbuchea/6f47e86d2510bce28f8e7f42ae84c716{} or mirror: {}https://hatter.ink/wiki/view_raw.action?__access_token=PUBLIC&id=42{} -"#, UNDER, END, UNDER, END)); - exit_with_error_message("Commit message rule is NOT matched"); - } +"#, BOLD, END, BOLD, END, UNDER, END, UNDER, END)); } -const RED: &str = "\x1B[91m"; -const GREEN: &str = "\x1B[92m"; -const BOLD: &str = "\x1B[1m"; -const UNDER: &str = "\x1B[4m"; -const END: &str = "\x1B[0m"; - fn install_commit_msg(force: bool) { let home_path = PathBuf::from(env::var("HOME").unwrap_or_else(|e| { exit_with_error_message(&format!("Get env HOME failed: {}!", e));