1use async_trait::async_trait;
2use clap::{CommandFactory, FromArgMatches, Parser};
3use tuwunel_core::Result;
4
5use crate::{
6 Context,
7 appservice::{self, AppserviceCommand},
8 debug::{self, DebugCommand},
9 federation::{self, FederationCommand},
10 integrity::{IntegrityCommand, process as process_integrity},
11 media::{self, MediaCommand},
12 query::{self, QueryCommand},
13 room::{self, RoomCommand},
14 server::{self, ServerCommand},
15 token::{self, TokenCommand},
16 user::{self, UserCommand},
17};
18
19pub(crate) struct Root;
21
22#[async_trait]
23impl tuwunel_service::admin::Command for Root {
24 fn clap(&self) -> clap::Command { <AdminCommand as CommandFactory>::command() }
25
26 async fn dispatch(
27 &self,
28 matches: clap::ArgMatches,
29 context: &tuwunel_service::admin::Context<'_>,
30 ) -> Result {
31 let command = <AdminCommand as FromArgMatches>::from_arg_matches(&matches)?;
32 let context = Context::new(context);
33
34 process(command, &context).await
35 }
36}
37
38#[derive(Debug, Parser)]
39#[command(name = "tuwunel", version = tuwunel_core::version())]
40pub(super) enum AdminCommand {
41 #[command(subcommand)]
42 Appservices(AppserviceCommand),
44
45 #[command(subcommand)]
46 Users(UserCommand),
48
49 #[command(subcommand)]
50 Rooms(RoomCommand),
52
53 #[command(subcommand)]
54 Federation(FederationCommand),
56
57 #[command(subcommand)]
58 Server(ServerCommand),
60
61 #[command(subcommand)]
62 Media(MediaCommand),
64
65 #[command(subcommand)]
66 Integrity(IntegrityCommand),
68
69 #[command(subcommand)]
70 Debug(DebugCommand),
72
73 #[command(subcommand)]
74 Query(QueryCommand),
76
77 #[command(subcommand)]
78 Token(TokenCommand),
80}
81
82#[tracing::instrument(skip_all, name = "command")]
83pub(super) async fn process(command: AdminCommand, context: &Context<'_>) -> Result {
84 use AdminCommand::*;
85
86 match command {
87 | Appservices(command) => appservice::process(command, context).await,
88 | Media(command) => media::process(command, context).await,
89 | Users(command) => user::process(command, context).await,
90 | Rooms(command) => room::process(command, context).await,
91 | Federation(command) => federation::process(command, context).await,
92 | Server(command) => server::process(command, context).await,
93 | Debug(command) => debug::process(command, context).await,
94 | Query(command) => query::process(command, context).await,
95 | Token(command) => token::process(command, context).await,
96 | Integrity(command) => process_integrity(command, context).await,
97 }
98}