gitmoji_rs/
lib.rs

1#![warn(missing_docs)]
2#![forbid(unsafe_code)]
3#![warn(clippy::perf)]
4// #![warn(clippy::nursery)]
5#![warn(clippy::pedantic)]
6#![allow(clippy::module_name_repetitions)]
7
8//! A [gitmoji](https://github.com/carloscuesta/gitmoji) interactive client for using gitmojis on commit messages.
9//!
10//! See <https://github.com/carloscuesta/gitmoji-cli>
11
12mod cli;
13mod cmd;
14mod error;
15mod git;
16mod model;
17
18use std::io::stdout;
19
20use clap::CommandFactory;
21use clap_complete::generate;
22use console::Term;
23
24pub use self::cli::*;
25pub use self::cmd::{
26    config as gitmoji_config, read_config_or_default, read_config_or_fail, write_config,
27};
28pub use self::error::*;
29pub use self::model::*;
30
31/// Exit code when a configuration is require but not found
32pub const EXIT_NO_CONFIG: i32 = 10;
33
34/// Exit code when a configuration cannot been updated
35pub const EXIT_CANNOT_UPDATE: i32 = 20;
36
37/// Running the gitmoji code
38///
39/// # Errors
40/// If the command fail
41pub async fn run(settings: Settings, term: &Term) -> Result<()> {
42    match settings.command {
43        Command::Init { default } => gitmoji_config(default, term).await,
44        Command::Commit { all, amend } => cmd::commit(all, amend, term).await,
45        Command::Update { url } => cmd::update_config(url).await,
46        Command::List => cmd::list().await,
47        Command::Search { text } => cmd::search(&text).await,
48        #[cfg(feature = "hook")]
49        Command::Hook(op) => match op {
50            HookOperation::Add => cmd::create_hook().await,
51            HookOperation::Remove => cmd::remove_hook().await,
52            HookOperation::Apply { dest, source } => cmd::apply_hook(dest, source, term).await,
53        },
54        Command::Completion { shell } => {
55            let mut cmd = <Settings as CommandFactory>::command();
56            generate(shell, &mut cmd, "gitmoji", &mut stdout());
57            Ok(())
58        }
59    }
60}