2024-07-27 00:11:41 +00:00
|
|
|
use clap::Subcommand;
|
2024-12-14 21:58:01 -05:00
|
|
|
use conduwuit::Result;
|
2024-04-20 14:44:31 -04:00
|
|
|
|
2024-07-27 00:11:41 +00:00
|
|
|
use crate::Command;
|
2024-04-20 14:44:31 -04:00
|
|
|
|
2024-07-27 00:11:41 +00:00
|
|
|
#[derive(Debug, Subcommand)]
|
2024-04-20 17:02:24 -04:00
|
|
|
/// All the getters and iterators from src/database/key_value/appservice.rs
|
2024-07-27 00:11:41 +00:00
|
|
|
pub(crate) enum AppserviceCommand {
|
|
|
|
|
/// - Gets the appservice registration info/details from the ID as a string
|
|
|
|
|
GetRegistration {
|
|
|
|
|
/// Appservice registration ID
|
|
|
|
|
appservice_id: Box<str>,
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/// - Gets all appservice registrations with their ID and registration info
|
|
|
|
|
All,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// All the getters and iterators from src/database/key_value/appservice.rs
|
2025-01-04 16:57:07 +00:00
|
|
|
pub(super) async fn process(subcommand: AppserviceCommand, context: &Command<'_>) -> Result {
|
2024-07-27 00:11:41 +00:00
|
|
|
let services = context.services;
|
|
|
|
|
|
2024-04-20 14:44:31 -04:00
|
|
|
match subcommand {
|
2024-12-15 00:05:47 -05:00
|
|
|
| AppserviceCommand::GetRegistration { appservice_id } => {
|
2024-04-20 14:44:31 -04:00
|
|
|
let timer = tokio::time::Instant::now();
|
2024-10-24 10:58:08 +00:00
|
|
|
let results = services.appservice.get_registration(&appservice_id).await;
|
2024-08-08 17:18:30 +00:00
|
|
|
|
2024-04-22 18:53:40 -04:00
|
|
|
let query_time = timer.elapsed();
|
|
|
|
|
|
2025-01-04 16:57:07 +00:00
|
|
|
write!(context, "Query completed in {query_time:?}:\n\n```rs\n{results:#?}\n```")
|
2024-04-22 18:53:40 -04:00
|
|
|
},
|
2024-12-15 00:05:47 -05:00
|
|
|
| AppserviceCommand::All => {
|
2024-04-22 18:53:40 -04:00
|
|
|
let timer = tokio::time::Instant::now();
|
2024-08-08 17:18:30 +00:00
|
|
|
let results = services.appservice.all().await;
|
2024-04-20 14:44:31 -04:00
|
|
|
let query_time = timer.elapsed();
|
|
|
|
|
|
2025-01-04 16:57:07 +00:00
|
|
|
write!(context, "Query completed in {query_time:?}:\n\n```rs\n{results:#?}\n```")
|
2024-04-20 14:44:31 -04:00
|
|
|
},
|
|
|
|
|
}
|
2025-01-04 16:57:07 +00:00
|
|
|
.await
|
2024-04-20 14:44:31 -04:00
|
|
|
}
|