create better structure for admin query commands

Signed-off-by: strawberry <strawberry@puppygock.gay>
This commit is contained in:
strawberry 2024-04-20 14:44:31 -04:00 committed by June
parent b93215d7f2
commit 2de4eea688
9 changed files with 225 additions and 201 deletions

View file

@ -0,0 +1,40 @@
use clap::Subcommand;
use ruma::events::room::message::RoomMessageEventContent;
use crate::{services, Result};
#[cfg_attr(test, derive(Debug))]
#[derive(Subcommand)]
/// All the getters and iterators from src/database/key_value/appservice.rs via
/// services()
pub(crate) enum Appservice {
/// - Gets the appservice registration info/details from the ID as a string
GetRegistration {
/// Appservice registration ID
appservice_id: Box<str>,
},
}
/// All the getters and iterators in key_value/appservice.rs via services()
pub(crate) async fn appservice(subcommand: Appservice) -> Result<RoomMessageEventContent> {
match subcommand {
Appservice::GetRegistration {
appservice_id,
} => {
let timer = tokio::time::Instant::now();
let results = services()
.appservice
.db
.get_registration(appservice_id.as_ref())?;
let query_time = timer.elapsed();
Ok(RoomMessageEventContent::text_html(
format!("Query completed in {query_time:?}:\n\n```\n{:?}```", results),
format!(
"<p>Query completed in {query_time:?}:</p>\n<pre><code>{:?}\n</code></pre>",
results
),
))
},
}
}