Debian Codegraph @

cli/src/commands/util/mod.rs

raw
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
15 mod backend;
16 mod completion;
17 mod config_schema;
18 mod exec;
19 mod gc;
20 mod install_man_pages;
21 mod markdown_help;
22 mod snapshot;
23
24 use clap::Subcommand;
25 use tracing::instrument;
26
27 use self::backend::UtilBackendCommand;
28 use self::backend::cmd_util_backend;
29 use self::completion::UtilCompletionArgs;
30 use self::completion::cmd_util_completion;
31 use self::config_schema::UtilConfigSchemaArgs;
32 use self::config_schema::cmd_util_config_schema;
33 use self::exec::UtilExecArgs;
34 use self::exec::cmd_util_exec;
35 use self::gc::UtilGcArgs;
36 use self::gc::cmd_util_gc;
37 use self::install_man_pages::UtilInstallManPagesArgs;
38 use self::install_man_pages::cmd_util_install_man_pages;
39 use self::markdown_help::UtilMarkdownHelp;
40 use self::markdown_help::cmd_util_markdown_help;
41 use self::snapshot::UtilSnapshotArgs;
42 use self::snapshot::cmd_util_snapshot;
43 use crate::cli_util::CommandHelper;
44 use crate::command_error::CommandError;
45 use crate::ui::Ui;
46
47 /// Infrequently used commands such as for generating shell completions
48 #[derive(Subcommand, Clone, Debug)]
49 pub(crate) enum UtilCommand {
50 #[command(subcommand)]
51 Backend(UtilBackendCommand),
52 Completion(UtilCompletionArgs),
53 ConfigSchema(UtilConfigSchemaArgs),
54 Exec(UtilExecArgs),
55 Gc(UtilGcArgs),
56 InstallManPages(UtilInstallManPagesArgs),
57 MarkdownHelp(UtilMarkdownHelp),
58 Snapshot(UtilSnapshotArgs),
59 }
60
61 #[instrument(skip_all)]
62 pub(crate) async fn cmd_util(
63 ui: &mut Ui,
64 command: &CommandHelper,
65 subcommand: &UtilCommand,
66 ) -> Result<(), CommandError> {
67 match subcommand {
68 UtilCommand::Backend(args) => cmd_util_backend(ui, command, args).await,
69 UtilCommand::Completion(args) => cmd_util_completion(ui, command, args).await,
70 UtilCommand::ConfigSchema(args) => cmd_util_config_schema(ui, command, args).await,
71 UtilCommand::Exec(args) => cmd_util_exec(ui, command, args).await,
72 UtilCommand::Gc(args) => cmd_util_gc(ui, command, args).await,
73 UtilCommand::InstallManPages(args) => cmd_util_install_man_pages(ui, command, args).await,
74 UtilCommand::MarkdownHelp(args) => cmd_util_markdown_help(ui, command, args).await,
75 UtilCommand::Snapshot(args) => cmd_util_snapshot(ui, command, args).await,
76 }
77 }