Skip to main content

tuwunel_admin/query/
appservice.rs

1use clap::Subcommand;
2use futures::TryStreamExt;
3use tuwunel_core::Result;
4
5use crate::Context;
6
7#[derive(Debug, Subcommand)]
8/// All the getters and iterators from src/service/appservice/
9pub(crate) enum AppserviceCommand {
10	/// - Gets the appservice registration info/details from the ID as a string
11	GetRegistration {
12		/// Appservice registration ID
13		appservice_id: String,
14	},
15
16	/// - Gets all appservice registrations with their ID and registration info
17	All,
18}
19
20/// All the getters and iterators from src/service/appservice/
21pub(super) async fn process(subcommand: AppserviceCommand, context: &Context<'_>) -> Result {
22	let services = context.services;
23
24	match subcommand {
25		| AppserviceCommand::GetRegistration { appservice_id } => {
26			let timer = tokio::time::Instant::now();
27			let results = services
28				.appservice
29				.get_registration(&appservice_id)
30				.await;
31
32			let query_time = timer.elapsed();
33
34			write!(context, "Query completed in {query_time:?}:\n\n```rs\n{results:#?}\n```")
35		},
36		| AppserviceCommand::All => {
37			let timer = tokio::time::Instant::now();
38			let results: Vec<_> = services
39				.appservice
40				.iter_db_ids()
41				.try_collect()
42				.await?;
43			let query_time = timer.elapsed();
44
45			write!(context, "Query completed in {query_time:?}:\n\n```rs\n{results:#?}\n```")
46		},
47	}
48	.await
49}