feat: add template
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
use clap::{App, Arg, ArgMatches};
|
||||
use crate::cmd::CommandError;
|
||||
use crate::template_regex::CommitMsgCheckRegex;
|
||||
|
||||
pub struct CommandImpl;
|
||||
|
||||
@@ -14,6 +15,7 @@ impl CommandImpl {
|
||||
information!("Verbose count: {}", verbose_count);
|
||||
information!(r#"Print using command line:
|
||||
commit-msg usage"#);
|
||||
CommitMsgCheckRegex::new_default();
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
17
src/cmd_install.rs
Normal file
17
src/cmd_install.rs
Normal file
@@ -0,0 +1,17 @@
|
||||
use clap::{ArgMatches, SubCommand, App};
|
||||
use crate::cmd::{Command, CommandError};
|
||||
|
||||
pub struct CommandImpl;
|
||||
|
||||
impl Command for CommandImpl {
|
||||
|
||||
fn name(&self) -> &str { "install" }
|
||||
|
||||
fn subcommand<'a>(&self) -> App<'a, 'a> {
|
||||
SubCommand::with_name(self.name()).about("Install subcommand")
|
||||
}
|
||||
|
||||
fn run(&self, _arg_matches: &ArgMatches, _sub_arg_matches: &ArgMatches) -> CommandError {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
@@ -8,7 +8,7 @@ impl Command for CommandImpl {
|
||||
fn name(&self) -> &str { "usage" }
|
||||
|
||||
fn subcommand<'a>(&self) -> App<'a, 'a> {
|
||||
SubCommand::with_name(self.name()).about("Sample subcommand")
|
||||
SubCommand::with_name(self.name()).about("Usage subcommand")
|
||||
}
|
||||
|
||||
fn run(&self, _arg_matches: &ArgMatches, _sub_arg_matches: &ArgMatches) -> CommandError {
|
||||
|
||||
@@ -3,13 +3,17 @@
|
||||
mod cmd;
|
||||
mod cmd_default;
|
||||
mod cmd_usage;
|
||||
mod cmd_install;
|
||||
mod template;
|
||||
mod template_regex;
|
||||
|
||||
use clap::App;
|
||||
use cmd::{Command, CommandError};
|
||||
|
||||
fn main() -> CommandError {
|
||||
let commands: Vec<Box<dyn Command>> = vec![
|
||||
Box::new(cmd_usage::CommandImpl)
|
||||
Box::new(cmd_usage::CommandImpl),
|
||||
Box::new(cmd_install::CommandImpl),
|
||||
];
|
||||
let mut app = App::new(env!("CARGO_PKG_NAME"))
|
||||
.version(env!("CARGO_PKG_VERSION"))
|
||||
|
||||
6
src/template.rs
Normal file
6
src/template.rs
Normal file
@@ -0,0 +1,6 @@
|
||||
|
||||
pub trait CommitMsgCheck {
|
||||
fn check(&self, msg: &str) -> bool;
|
||||
|
||||
fn print_hint(&self);
|
||||
}
|
||||
50
src/template_regex.rs
Normal file
50
src/template_regex.rs
Normal file
@@ -0,0 +1,50 @@
|
||||
use regex::Regex;
|
||||
use rust_util::util_term::{BOLD, UNDER, END};
|
||||
use crate::template::CommitMsgCheck;
|
||||
|
||||
const DEFAULT_COMMIT_MSG_REGEXP: &str = "^(feat|fix|docs|style|refactor|test|chore)(\\([\\w\\-_.]+\\))?:\\s*.*";
|
||||
|
||||
pub struct CommitMsgCheckRegex {
|
||||
regex: Regex,
|
||||
hint: String,
|
||||
}
|
||||
|
||||
impl CommitMsgCheck for CommitMsgCheckRegex {
|
||||
fn check(&self, msg: &str) -> bool {
|
||||
self.regex.is_match(msg)
|
||||
}
|
||||
|
||||
fn print_hint(&self) {
|
||||
println!("[USAGE] {}", self.hint);
|
||||
}
|
||||
}
|
||||
|
||||
impl CommitMsgCheckRegex {
|
||||
pub fn new_default() -> Self {
|
||||
Self {
|
||||
regex: Regex::new(DEFAULT_COMMIT_MSG_REGEXP).unwrap(),
|
||||
hint: format!(r#"Please follow the commit spec:
|
||||
Format: {b}<type>{e}(<scope>){b}: <subject>{e}
|
||||
<scope> is optional
|
||||
|
||||
{b}feat{e}: add hat wobble
|
||||
^--^ ^------------^
|
||||
| |
|
||||
| +-> Summary in present tense.
|
||||
|
|
||||
+-------> Type: chore, docs, feat, fix, refactor, style, or test.
|
||||
|
||||
{b}feat{e} : new feature for the user, not a new feature for build script
|
||||
{b}fix{e} : bug fix for the user, not a fix to a build script
|
||||
{b}docs{e} : changes to the documentation
|
||||
{b}style{e} : formatting, missing semi colons, etc; no production code change
|
||||
{b}refactor{e} : refactoring production code, eg. renaming a variable
|
||||
{b}test{e} : adding missing tests, refactoring tests; no production code change
|
||||
{b}chore{e} : updating grunt tasks etc; no production code change
|
||||
|
||||
Reference: {u}https://gist.github.com/joshbuchea/6f47e86d2510bce28f8e7f42ae84c716{e}
|
||||
or mirror: {u}https://hatter.ink/wiki/view_raw.action?__access_token=PUBLIC&id=42{e}
|
||||
"#, b = BOLD, e = END, u = UNDER),
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user