1mod abandon;
16mod absorb;
17mod arrange;
18#[cfg(feature = "bench")]
19mod bench;
20mod bisect;
21mod bookmark;
22mod commit;
23mod config;
24mod debug;
25mod describe;
26mod diff;
27mod diffedit;
28mod duplicate;
29mod edit;
30mod evolog;
31mod file;
32mod fix;
33#[cfg(feature = "git")]
34mod gerrit;
35#[cfg(feature = "git")]
36mod git;
37mod help;
38mod interdiff;
39mod log;
40mod metaedit;
41mod new;
42mod next;
43mod operation;
44mod parallelize;
45mod prev;
46mod rebase;
47mod redo;
48mod resolve;
49mod restore;
50mod revert;
51mod root;
52mod run;
53mod show;
54mod sign;
55mod simplify_parents;
56mod sparse;
57mod split;
58mod squash;
59mod status;
60mod tag;
61mod undo;
62mod unsign;
63mod util;
64mod version;
65mod workspace;
66
67use std::fmt::Debug;
68
69use clap::CommandFactory as _;
70use clap::FromArgMatches as _;
71use clap::Subcommand as _;
72use clap::builder::Styles;
73use clap::builder::styling::AnsiColor;
74use clap_complete::engine::SubcommandCandidates;
75use tracing::instrument;
76
77use crate::cli_util::Args;
78use crate::cli_util::CommandHelper;
79use crate::command_error::CommandError;
80use crate::complete;
81use crate::ui::Ui;
82
83const STYLES: Styles = Styles::styled()
84 .header(AnsiColor::Yellow.on_default().bold())
85 .usage(AnsiColor::Yellow.on_default().bold())
86 .literal(AnsiColor::Green.on_default().bold())
87 .placeholder(AnsiColor::Green.on_default());
88
89#[derive(clap::Parser, Clone, Debug)]
90#[command(styles = STYLES)]
91#[command(disable_help_subcommand = true)]
92#[command(after_long_help = help::show_keyword_hint_after_help())]
93#[command(add = SubcommandCandidates::new(complete::aliases))]
94enum Command {
95 Abandon(abandon::AbandonArgs),
96 Absorb(absorb::AbsorbArgs),
97 Arrange(arrange::ArrangeArgs),
98 #[cfg(feature = "bench")]
99 #[command(subcommand)]
100 Bench(bench::BenchCommand),
101 #[command(subcommand)]
102 Bisect(bisect::BisectCommand),
103 #[command(subcommand)]
104 Bookmark(bookmark::BookmarkCommand),
105 Commit(commit::CommitArgs),
106 #[command(subcommand)]
107 Config(config::ConfigCommand),
108 #[command(subcommand)]
109 Debug(debug::DebugCommand),
110 Describe(describe::DescribeArgs),
111 Diff(diff::DiffArgs),
112 Diffedit(diffedit::DiffeditArgs),
113 Duplicate(duplicate::DuplicateArgs),
114 Edit(edit::EditArgs),
115 #[command(alias = "obslog", visible_alias = "evolution-log")]
116 Evolog(evolog::EvologArgs),
117 #[command(subcommand)]
118 File(file::FileCommand),
119 Fix(fix::FixArgs),
120 #[cfg(feature = "git")]
121 #[command(subcommand)]
122 Gerrit(gerrit::GerritCommand),
123 #[cfg(feature = "git")]
124 #[command(subcommand)]
125 Git(git::GitCommand),
126 Help(help::HelpArgs),
127 Interdiff(interdiff::InterdiffArgs),
128 Log(log::LogArgs),
129 Metaedit(metaedit::MetaeditArgs),
130 New(new::NewArgs),
131 Next(next::NextArgs),
132 #[command(subcommand)]
133 #[command(visible_alias = "op")]
134 Operation(operation::OperationCommand),
135 Parallelize(parallelize::ParallelizeArgs),
136 Prev(prev::PrevArgs),
137 Rebase(rebase::RebaseArgs),
138 Redo(redo::RedoArgs),
139 Resolve(resolve::ResolveArgs),
140 Restore(restore::RestoreArgs),
141 Revert(revert::RevertArgs),
142 Root(root::RootArgs),
143 #[command(hide = true)]
144 Run(run::RunArgs),
146 Show(show::ShowArgs),
147 Sign(sign::SignArgs),
148 SimplifyParents(simplify_parents::SimplifyParentsArgs),
149 #[command(subcommand)]
150 Sparse(sparse::SparseCommand),
151 Split(split::SplitArgs),
152 Squash(squash::SquashArgs),
153 Status(status::StatusArgs),
154 #[command(subcommand)]
155 Tag(tag::TagCommand),
156 Undo(undo::UndoArgs),
157 Unsign(unsign::UnsignArgs),
158 #[command(subcommand)]
159 Util(util::UtilCommand),
160 Version(version::VersionArgs),
161 #[command(subcommand)]
162 Workspace(workspace::WorkspaceCommand),
163}
164
165pub fn default_app() -> clap::Command {
166 Command::augment_subcommands(Args::command())
167}
168
169#[instrument(skip_all)]
170pub async fn run_command(ui: &mut Ui, command_helper: &CommandHelper) -> Result<(), CommandError> {
171 let subcommand = Command::from_arg_matches(command_helper.matches()).unwrap();
172 match &subcommand {
173 Command::Abandon(args) => abandon::cmd_abandon(ui, command_helper, args).await,
174 Command::Absorb(args) => absorb::cmd_absorb(ui, command_helper, args).await,
175 #[cfg(feature = "bench")]
176 Command::Bench(args) => bench::cmd_bench(ui, command_helper, args).await,
177 Command::Bisect(args) => bisect::cmd_bisect(ui, command_helper, args).await,
178 Command::Bookmark(args) => bookmark::cmd_bookmark(ui, command_helper, args).await,
179 Command::Commit(args) => commit::cmd_commit(ui, command_helper, args).await,
180 Command::Config(args) => config::cmd_config(ui, command_helper, args).await,
181 Command::Debug(args) => debug::cmd_debug(ui, command_helper, args).await,
182 Command::Describe(args) => describe::cmd_describe(ui, command_helper, args).await,
183 Command::Diff(args) => diff::cmd_diff(ui, command_helper, args).await,
184 Command::Diffedit(args) => diffedit::cmd_diffedit(ui, command_helper, args).await,
185 Command::Duplicate(args) => duplicate::cmd_duplicate(ui, command_helper, args).await,
186 Command::Edit(args) => edit::cmd_edit(ui, command_helper, args).await,
187 Command::Evolog(args) => evolog::cmd_evolog(ui, command_helper, args).await,
188 Command::File(args) => file::cmd_file(ui, command_helper, args).await,
189 Command::Fix(args) => fix::cmd_fix(ui, command_helper, args).await,
190 #[cfg(feature = "git")]
191 Command::Gerrit(sub_args) => gerrit::cmd_gerrit(ui, command_helper, sub_args).await,
192 #[cfg(feature = "git")]
193 Command::Git(args) => git::cmd_git(ui, command_helper, args).await,
194 Command::Help(args) => help::cmd_help(ui, command_helper, args).await,
195 Command::Arrange(args) => arrange::cmd_arrange(ui, command_helper, args).await,
196 Command::Interdiff(args) => interdiff::cmd_interdiff(ui, command_helper, args).await,
197 Command::Log(args) => log::cmd_log(ui, command_helper, args).await,
198 Command::Metaedit(args) => metaedit::cmd_metaedit(ui, command_helper, args).await,
199 Command::New(args) => new::cmd_new(ui, command_helper, args).await,
200 Command::Next(args) => next::cmd_next(ui, command_helper, args).await,
201 Command::Operation(args) => operation::cmd_operation(ui, command_helper, args).await,
202 Command::Parallelize(args) => parallelize::cmd_parallelize(ui, command_helper, args).await,
203 Command::Prev(args) => prev::cmd_prev(ui, command_helper, args).await,
204 Command::Rebase(args) => rebase::cmd_rebase(ui, command_helper, args).await,
205 Command::Redo(args) => redo::cmd_redo(ui, command_helper, args).await,
206 Command::Resolve(args) => resolve::cmd_resolve(ui, command_helper, args).await,
207 Command::Restore(args) => restore::cmd_restore(ui, command_helper, args).await,
208 Command::Revert(args) => revert::cmd_revert(ui, command_helper, args).await,
209 Command::Root(args) => root::cmd_root(ui, command_helper, args).await,
210 Command::Run(args) => run::cmd_run(ui, command_helper, args).await,
211 Command::SimplifyParents(args) => {
212 simplify_parents::cmd_simplify_parents(ui, command_helper, args).await
213 }
214 Command::Show(args) => show::cmd_show(ui, command_helper, args).await,
215 Command::Sign(args) => sign::cmd_sign(ui, command_helper, args).await,
216 Command::Sparse(args) => sparse::cmd_sparse(ui, command_helper, args).await,
217 Command::Split(args) => split::cmd_split(ui, command_helper, args).await,
218 Command::Squash(args) => squash::cmd_squash(ui, command_helper, args).await,
219 Command::Status(args) => status::cmd_status(ui, command_helper, args).await,
220 Command::Tag(args) => tag::cmd_tag(ui, command_helper, args).await,
221 Command::Undo(args) => undo::cmd_undo(ui, command_helper, args).await,
222 Command::Unsign(args) => unsign::cmd_unsign(ui, command_helper, args).await,
223 Command::Util(args) => util::cmd_util(ui, command_helper, args).await,
224 Command::Version(args) => version::cmd_version(ui, command_helper, args).await,
225 Command::Workspace(args) => workspace::cmd_workspace(ui, command_helper, args).await,
226 }
227}
228
229#[cfg(test)]
230mod tests {
231 use super::*;
232
233 #[test]
234 fn verify_app() {
235 default_app().debug_assert();
236 }
237}