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 history;
17mod model;
18mod recovery;
19
20use std::io::stdout;
21
22use clap::CommandFactory;
23use clap_complete::generate;
24use console::Term;
25
26pub use self::cli::*;
27pub use self::cmd::{
28    config as gitmoji_config, read_config_or_default, read_config_or_fail, write_config,
29};
30pub use self::error::*;
31pub use self::history::ScopeHistory;
32pub use self::model::*;
33
34/// Exit code when a configuration is require but not found
35pub const EXIT_NO_CONFIG: i32 = 10;
36
37/// Exit code when a configuration cannot been updated
38pub const EXIT_CANNOT_UPDATE: i32 = 20;
39
40/// Running the gitmoji code
41///
42/// # Errors
43/// If the command fail
44pub async fn run(settings: Settings, term: &Term) -> Result<()> {
45    match settings.command {
46        Command::Init { default } => gitmoji_config(default, term).await,
47        Command::Commit {
48            all,
49            amend,
50            extra_args,
51        } => cmd::commit(all, amend, &extra_args, term).await,
52        Command::Update { url } => cmd::update_config(url).await,
53        Command::List => cmd::list().await,
54        Command::Search { text } => cmd::search(&text).await,
55        #[cfg(feature = "hook")]
56        Command::Hook(op) => match op {
57            HookOperation::Add => cmd::create_hook().await,
58            HookOperation::Remove => cmd::remove_hook().await,
59            HookOperation::Apply { dest, source } => cmd::apply_hook(dest, source, term).await,
60        },
61        Command::Completion { shell } => {
62            let mut cmd = <Settings as CommandFactory>::command();
63            generate(shell, &mut cmd, "gitmoji", &mut stdout());
64            Ok(())
65        }
66    }
67}