-
-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathmain.rs
More file actions
68 lines (55 loc) · 1.46 KB
/
main.rs
File metadata and controls
68 lines (55 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#![allow(
clippy::struct_field_names,
clippy::multiple_crate_versions,
clippy::module_name_repetitions
)]
mod commit;
mod commit_message;
mod commit_pattern;
mod config;
use anyhow::Result;
use clap::Parser;
use std::path::PathBuf;
use commit::{
check_staged_files, commit, git_add_all_modified, pre_commit_check, read_cached_commit,
write_cached_commit,
};
use commit_message::make_message_commit;
#[derive(Parser, Debug)]
#[command(about, author, version)]
struct Args {
/// Custom configuration file path
#[arg(short, long)]
config: Option<PathBuf>,
/// Use as hook
#[arg(long)]
hook: bool,
/// Retry commit with the same message as the last one
#[arg(short, long)]
retry: bool,
/// Add all modified files into staging
#[arg(short, long)]
all: bool,
}
fn main() -> Result<()> {
let args = Args::parse();
if args.all {
git_add_all_modified()?;
}
check_staged_files()?;
let pattern = config::get_pattern(args.config)?;
if args.retry {
let commit_message = read_cached_commit()?;
pre_commit_check(pattern.config.pre_commit, &commit_message)?;
commit(&commit_message)?;
return Ok(());
}
let commit_message = make_message_commit(pattern.clone())?;
write_cached_commit(&commit_message)?;
pre_commit_check(pattern.config.pre_commit, &commit_message)?;
if args.hook {
return Ok(());
}
commit(&commit_message)?;
Ok(())
}