Skip to main content

jj_cli/commands/
mod.rs

1// Copyright 2020 The Jujutsu Authors
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// https://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15mod 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    Run(run::RunArgs),
144    Show(show::ShowArgs),
145    Sign(sign::SignArgs),
146    SimplifyParents(simplify_parents::SimplifyParentsArgs),
147    #[command(subcommand)]
148    Sparse(sparse::SparseCommand),
149    Split(split::SplitArgs),
150    Squash(squash::SquashArgs),
151    Status(status::StatusArgs),
152    #[command(subcommand)]
153    Tag(tag::TagCommand),
154    Undo(undo::UndoArgs),
155    Unsign(unsign::UnsignArgs),
156    #[command(subcommand)]
157    Util(util::UtilCommand),
158    Version(version::VersionArgs),
159    #[command(subcommand)]
160    Workspace(workspace::WorkspaceCommand),
161}
162
163pub fn default_app() -> clap::Command {
164    Command::augment_subcommands(Args::command())
165}
166
167#[instrument(skip_all)]
168pub async fn run_command(ui: &mut Ui, command_helper: &CommandHelper) -> Result<(), CommandError> {
169    let subcommand = Command::from_arg_matches(command_helper.matches()).unwrap();
170    match &subcommand {
171        Command::Abandon(args) => abandon::cmd_abandon(ui, command_helper, args).await,
172        Command::Absorb(args) => absorb::cmd_absorb(ui, command_helper, args).await,
173        #[cfg(feature = "bench")]
174        Command::Bench(args) => bench::cmd_bench(ui, command_helper, args).await,
175        Command::Bisect(args) => bisect::cmd_bisect(ui, command_helper, args).await,
176        Command::Bookmark(args) => bookmark::cmd_bookmark(ui, command_helper, args).await,
177        Command::Commit(args) => commit::cmd_commit(ui, command_helper, args).await,
178        Command::Config(args) => config::cmd_config(ui, command_helper, args).await,
179        Command::Debug(args) => debug::cmd_debug(ui, command_helper, args).await,
180        Command::Describe(args) => describe::cmd_describe(ui, command_helper, args).await,
181        Command::Diff(args) => diff::cmd_diff(ui, command_helper, args).await,
182        Command::Diffedit(args) => diffedit::cmd_diffedit(ui, command_helper, args).await,
183        Command::Duplicate(args) => duplicate::cmd_duplicate(ui, command_helper, args).await,
184        Command::Edit(args) => edit::cmd_edit(ui, command_helper, args).await,
185        Command::Evolog(args) => evolog::cmd_evolog(ui, command_helper, args).await,
186        Command::File(args) => file::cmd_file(ui, command_helper, args).await,
187        Command::Fix(args) => fix::cmd_fix(ui, command_helper, args).await,
188        #[cfg(feature = "git")]
189        Command::Gerrit(sub_args) => gerrit::cmd_gerrit(ui, command_helper, sub_args).await,
190        #[cfg(feature = "git")]
191        Command::Git(args) => git::cmd_git(ui, command_helper, args).await,
192        Command::Help(args) => help::cmd_help(ui, command_helper, args).await,
193        Command::Arrange(args) => arrange::cmd_arrange(ui, command_helper, args).await,
194        Command::Interdiff(args) => interdiff::cmd_interdiff(ui, command_helper, args).await,
195        Command::Log(args) => log::cmd_log(ui, command_helper, args).await,
196        Command::Metaedit(args) => metaedit::cmd_metaedit(ui, command_helper, args).await,
197        Command::New(args) => new::cmd_new(ui, command_helper, args).await,
198        Command::Next(args) => next::cmd_next(ui, command_helper, args).await,
199        Command::Operation(args) => operation::cmd_operation(ui, command_helper, args).await,
200        Command::Parallelize(args) => parallelize::cmd_parallelize(ui, command_helper, args).await,
201        Command::Prev(args) => prev::cmd_prev(ui, command_helper, args).await,
202        Command::Rebase(args) => rebase::cmd_rebase(ui, command_helper, args).await,
203        Command::Redo(args) => redo::cmd_redo(ui, command_helper, args).await,
204        Command::Resolve(args) => resolve::cmd_resolve(ui, command_helper, args).await,
205        Command::Restore(args) => restore::cmd_restore(ui, command_helper, args).await,
206        Command::Revert(args) => revert::cmd_revert(ui, command_helper, args).await,
207        Command::Root(args) => root::cmd_root(ui, command_helper, args).await,
208        Command::Run(args) => run::cmd_run(ui, command_helper, args).await,
209        Command::SimplifyParents(args) => {
210            simplify_parents::cmd_simplify_parents(ui, command_helper, args).await
211        }
212        Command::Show(args) => show::cmd_show(ui, command_helper, args).await,
213        Command::Sign(args) => sign::cmd_sign(ui, command_helper, args).await,
214        Command::Sparse(args) => sparse::cmd_sparse(ui, command_helper, args).await,
215        Command::Split(args) => split::cmd_split(ui, command_helper, args).await,
216        Command::Squash(args) => squash::cmd_squash(ui, command_helper, args).await,
217        Command::Status(args) => status::cmd_status(ui, command_helper, args).await,
218        Command::Tag(args) => tag::cmd_tag(ui, command_helper, args).await,
219        Command::Undo(args) => undo::cmd_undo(ui, command_helper, args).await,
220        Command::Unsign(args) => unsign::cmd_unsign(ui, command_helper, args).await,
221        Command::Util(args) => util::cmd_util(ui, command_helper, args).await,
222        Command::Version(args) => version::cmd_version(ui, command_helper, args).await,
223        Command::Workspace(args) => workspace::cmd_workspace(ui, command_helper, args).await,
224    }
225}
226
227#[cfg(test)]
228mod tests {
229    use super::*;
230
231    #[test]
232    fn verify_app() {
233        default_app().debug_assert();
234    }
235}