|
15 | 15 | use crate::built_info; |
16 | 16 | use clap::{Parser, Subcommand}; |
17 | 17 |
|
| 18 | +/// Command-line interface for `aigitcommit`. |
| 19 | +/// |
| 20 | +/// Boolean flags omit `default_value_t = false` because that is already the |
| 21 | +/// default for `bool`. Optional positional arguments omit `required = false` |
| 22 | +/// for the same reason. This keeps the attribute noise down and makes the |
| 23 | +/// definition easier to scan. |
18 | 24 | #[derive(Debug, Parser)] |
19 | | -#[command(name = built_info::PKG_NAME, about = built_info::PKG_DESCRIPTION, version = built_info::PKG_VERSION, author = built_info::PKG_AUTHORS)] |
| 25 | +#[command( |
| 26 | + name = built_info::PKG_NAME, |
| 27 | + about = built_info::PKG_DESCRIPTION, |
| 28 | + version = built_info::PKG_VERSION, |
| 29 | + author = built_info::PKG_AUTHORS, |
| 30 | +)] |
20 | 31 | pub struct Cli { |
21 | 32 | #[command(subcommand)] |
22 | 33 | pub command: Option<Command>, |
23 | | - #[arg( |
24 | | - default_value = ".", |
25 | | - help = r#"Specify the file path to repository directory. |
26 | | -If not specified, the current directory will be used"#, |
27 | | - required = false |
28 | | - )] |
| 34 | + |
| 35 | + /// Path to the repository directory. Defaults to the current directory. |
| 36 | + #[arg(default_value = ".")] |
29 | 37 | pub repo_path: String, |
30 | 38 |
|
31 | | - #[arg( |
32 | | - long, |
33 | | - short, |
34 | | - help = "Verbose mode", |
35 | | - default_value_t = false, |
36 | | - required = false |
37 | | - )] |
| 39 | + /// Enable verbose (TRACE-level) logging. |
| 40 | + #[arg(long, short)] |
38 | 41 | pub verbose: bool, |
39 | 42 |
|
40 | | - #[arg( |
41 | | - long, |
42 | | - help = "Check the openai api key and model name whether is available", |
43 | | - default_value_t = false, |
44 | | - required = false |
45 | | - )] |
| 43 | + /// Verify that the configured OpenAI model is available. |
| 44 | + #[arg(long)] |
46 | 45 | pub check_model: bool, |
47 | 46 |
|
48 | | - #[arg( |
49 | | - long, |
50 | | - help = "Prompt the commit after generating the message", |
51 | | - default_value_t = false, |
52 | | - required = false |
53 | | - )] |
| 47 | + /// Prompt to commit after generating the message. |
| 48 | + #[arg(long)] |
54 | 49 | pub commit: bool, |
55 | 50 |
|
56 | | - #[arg( |
57 | | - long, |
58 | | - help = "Mark whether the commit is a signoff commit", |
59 | | - default_value_t = false, |
60 | | - required = false |
61 | | - )] |
| 51 | + /// Append a `Signed-off-by` trailer to the commit message. |
| 52 | + #[arg(long)] |
62 | 53 | pub signoff: bool, |
63 | 54 |
|
64 | | - #[arg( |
65 | | - long, |
66 | | - short, |
67 | | - help = "Accept the commit message without prompting", |
68 | | - default_value_t = false, |
69 | | - required = false |
70 | | - )] |
| 55 | + /// Accept the generated commit message without prompting. |
| 56 | + #[arg(long, short)] |
71 | 57 | pub yes: bool, |
72 | 58 |
|
73 | | - #[arg( |
74 | | - long, |
75 | | - help = "Copy the commit message to clipboard", |
76 | | - default_value_t = false, |
77 | | - required = false |
78 | | - )] |
| 59 | + /// Copy the generated commit message to the system clipboard. |
| 60 | + #[arg(long)] |
79 | 61 | pub copy_to_clipboard: bool, |
80 | 62 |
|
81 | | - #[arg( |
82 | | - long, |
83 | | - help = "Print the commit message in JSON format", |
84 | | - default_value_t = false, |
85 | | - required = false |
86 | | - )] |
| 63 | + /// Print the commit message as JSON. |
| 64 | + #[arg(long)] |
87 | 65 | pub json: bool, |
88 | 66 |
|
89 | | - #[arg( |
90 | | - long, |
91 | | - help = "Print the commit message in a table format", |
92 | | - default_value_t = false, |
93 | | - required = false |
94 | | - )] |
| 67 | + /// Print the commit message as plain text instead of a table. |
| 68 | + #[arg(long)] |
95 | 69 | pub no_table: bool, |
96 | 70 |
|
97 | | - #[arg( |
98 | | - long, |
99 | | - help = "Check current environment variables for OpenAI API key and model name", |
100 | | - default_value_t = false, |
101 | | - required = false |
102 | | - )] |
| 71 | + /// Print the values of the OpenAI-related environment variables and exit. |
| 72 | + #[arg(long)] |
103 | 73 | pub check_env: bool, |
104 | 74 |
|
105 | | - #[arg( |
106 | | - long, |
107 | | - short, |
108 | | - default_value = "", |
109 | | - help = "Save the commit message to a file", |
110 | | - required = false |
111 | | - )] |
| 75 | + /// Save the generated commit message to the given file. |
| 76 | + #[arg(long, short, default_value = "")] |
112 | 77 | pub save: String, |
113 | 78 |
|
114 | | - #[arg( |
115 | | - long, |
116 | | - help = "Disable the local cache and always request a fresh message from the API", |
117 | | - default_value_t = false, |
118 | | - required = false |
119 | | - )] |
| 79 | + /// Bypass the local cache and always request a fresh message from the API. |
| 80 | + #[arg(long)] |
120 | 81 | pub no_cache: bool, |
121 | 82 |
|
122 | | - #[arg( |
123 | | - long, |
124 | | - help = "Clear the local cache for the current repository and exit", |
125 | | - default_value_t = false, |
126 | | - required = false |
127 | | - )] |
| 83 | + /// Clear the local cache for the current repository and exit. |
| 84 | + #[arg(long)] |
128 | 85 | pub clear_cache: bool, |
129 | 86 | } |
130 | 87 |
|
131 | 88 | #[derive(Debug, Subcommand)] |
132 | 89 | pub enum Command { |
133 | | - #[command( |
134 | | - name = "install-hook", |
135 | | - about = "Install git hook script into the specified repository directory" |
136 | | - )] |
| 90 | + /// Install the `prepare-commit-msg` git hook into the given repository. |
| 91 | + #[command(name = "install-hook")] |
137 | 92 | InstallHook { |
138 | | - #[arg( |
139 | | - default_value = ".", |
140 | | - help = "Repository directory to install the git hook into", |
141 | | - required = false |
142 | | - )] |
| 93 | + /// Repository directory to install the git hook into. |
| 94 | + #[arg(default_value = ".")] |
143 | 95 | repo_path: String, |
144 | 96 | }, |
145 | 97 | } |
146 | 98 |
|
147 | 99 | #[cfg(test)] |
148 | | -mod tests {} |
| 100 | +mod tests { |
| 101 | + use super::*; |
| 102 | + use clap::CommandFactory; |
| 103 | + |
| 104 | + #[test] |
| 105 | + fn cli_definition_is_valid() { |
| 106 | + // Catches programmer mistakes (duplicate short flags, bad attrs) |
| 107 | + // at test time instead of at first user invocation. |
| 108 | + Cli::command().debug_assert(); |
| 109 | + } |
| 110 | +} |
0 commit comments