gitmoji_rs/
cli.rs

1use clap::{Parser, Subcommand};
2use clap_complete::Shell;
3use url::Url;
4
5#[derive(Debug, Clone, Parser)]
6#[clap(author, version, about, long_about = None)]
7/// A gitmoji client for using emojis on commit messages.
8pub struct Settings {
9    #[clap(subcommand)]
10    pub(crate) command: Command,
11
12    #[clap(short, long)]
13    /// Verbose mode
14    verbose: bool,
15}
16
17impl Settings {
18    /// Is verbose mode toggled
19    #[must_use]
20    pub const fn verbose(&self) -> bool {
21        self.verbose
22    }
23}
24
25#[derive(Debug, Clone, Subcommand)]
26/// Available commands
27pub enum Command {
28    /// Setup gitmoji preferences
29    Init {
30        // TODO [#3] allow local
31        #[clap(long)]
32        /// Use default configuration without interactivity
33        default: bool,
34    },
35
36    /// Interactively commit using the prompts
37    Commit {
38        #[clap(long)]
39        /// Add the `--all` flag for git commit command
40        all: bool,
41
42        #[clap(long)]
43        /// Add the `--amend` flag for git commit command
44        amend: bool,
45
46        #[clap(last = true)]
47        /// Extra arguments to pass to `git commit`
48        extra_args: Vec<String>,
49    },
50
51    /// Sync emoji list with the repository
52    Update {
53        /// Change the update URL
54        url: Option<Url>,
55    },
56
57    /// List all available gitmojis
58    List,
59
60    /// Search gitmojis
61    Search {
62        /// Search text
63        text: String,
64    },
65
66    /// Create or remove git commit hook
67    #[cfg(feature = "hook")]
68    #[clap(subcommand)]
69    Hook(HookOperation),
70
71    /// Generate completion for shell
72    Completion {
73        /// The shell (bash, zsh, fish, elvish, powershell)
74        shell: Shell,
75    },
76}
77
78#[cfg(feature = "hook")]
79#[derive(Debug, Clone, Subcommand)]
80/// Available hook operation
81pub enum HookOperation {
82    /// Add the hook
83    Add,
84    /// Remove the hook
85    Remove,
86    /// (Used by the hook to create commit message)
87    Apply {
88        /// The commit message file
89        dest: std::path::PathBuf,
90
91        /// The commit source
92        source: Option<String>,
93    },
94}