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 /// Get the command
25 #[must_use]
26 pub const fn command(&self) -> &Command {
27 &self.command
28 }
29}
30
31#[derive(Debug, Clone, Subcommand)]
32/// Available commands
33pub enum Command {
34 /// Setup gitmoji preferences
35 Init {
36 // TODO [#3] allow local
37 #[clap(long)]
38 /// Use default configuration without interactivity
39 default: bool,
40 },
41
42 /// Interactively commit using the prompts
43 Commit {
44 #[clap(long)]
45 /// Add the `--all` flag for git commit command
46 all: bool,
47
48 #[clap(long)]
49 /// Add the `--amend` flag for git commit command
50 amend: bool,
51 },
52
53 /// Sync emoji list with the repository
54 Update {
55 /// Change the update URL
56 url: Option<Url>,
57 },
58
59 /// List all available gitmojis
60 List,
61
62 /// Search gitmojis
63 Search {
64 /// Search text
65 text: String,
66 },
67
68 /// Create or remove git commit hook
69 #[cfg(feature = "hook")]
70 #[clap(subcommand)]
71 Hook(HookOperation),
72
73 /// Generate completion for shell
74 Completion {
75 /// The shell (bash, zsh, fish, elvish, powershell)
76 shell: Shell,
77 },
78}
79
80#[cfg(feature = "hook")]
81#[derive(Debug, Clone, Subcommand)]
82/// Available hook operation
83pub enum HookOperation {
84 /// Add the hook
85 Add,
86 /// Remove the hook
87 Remove,
88 /// (Used by the hook to create commit message)
89 Apply {
90 /// The commit message file
91 dest: std::path::PathBuf,
92
93 /// The commit source
94 source: Option<String>,
95 },
96}