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
#![warn(missing_docs)]
#![forbid(unsafe_code)]
#![warn(clippy::perf)]
#![warn(clippy::pedantic)]
#![allow(clippy::module_name_repetitions)]
mod cli;
mod cmd;
mod error;
mod git;
mod model;
use std::io::stdout;
use clap::CommandFactory;
use clap_complete::generate;
use console::Term;
pub use self::cli::*;
pub use self::cmd::{
config as gitmoji_config, read_config_or_default, read_config_or_fail, write_config,
};
pub use self::error::*;
pub use self::model::*;
pub const EXIT_NO_CONFIG: i32 = 10;
pub const EXIT_CANNOT_UPDATE: i32 = 20;
pub async fn run(settings: Settings, term: &Term) -> Result<()> {
match settings.command {
Command::Init { default } => gitmoji_config(default, term).await,
Command::Commit { all, amend } => cmd::commit(all, amend, term).await,
Command::Update { url } => cmd::update_config(url).await,
Command::List => cmd::list().await,
Command::Search { text } => cmd::search(&text).await,
#[cfg(feature = "hook")]
Command::Hook(op) => match op {
HookOperation::Add => cmd::create_hook().await,
HookOperation::Remove => cmd::remove_hook().await,
HookOperation::Apply { dest, source } => cmd::apply_hook(dest, source, term).await,
},
Command::Completion { shell } => {
let mut cmd = <Settings as CommandFactory>::command();
generate(shell, &mut cmd, "gitmoji", &mut stdout());
Ok(())
}
}
}