From 4e975887cf2e2e7f81d28789fca2fc4a2fb32657 Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Wed, 24 Jul 2024 23:53:48 +0000 Subject: [PATCH] add command to list features Signed-off-by: Jason Volk --- src/admin/server/commands.rs | 45 +++++++++++++++++++++++++++++++++++- src/admin/server/mod.rs | 17 ++++++++++++++ 2 files changed, 61 insertions(+), 1 deletion(-) diff --git a/src/admin/server/commands.rs b/src/admin/server/commands.rs index e4503736..c30f8f87 100644 --- a/src/admin/server/commands.rs +++ b/src/admin/server/commands.rs @@ -1,4 +1,6 @@ -use conduit::{utils::time, warn, Err, Result}; +use std::fmt::Write; + +use conduit::{info, utils::time, warn, Err, Result}; use ruma::events::room::message::RoomMessageEventContent; use crate::services; @@ -19,6 +21,47 @@ pub(super) async fn show_config(_body: Vec<&str>) -> Result, available: bool, enabled: bool, comma: bool, +) -> Result { + let delim = if comma { + "," + } else { + " " + }; + if enabled && !available { + let features = info::rustc::features().join(delim); + let out = format!("```\n{features}\n```"); + return Ok(RoomMessageEventContent::text_markdown(out)); + } + + if available && !enabled { + let features = info::cargo::features().join(delim); + let out = format!("```\n{features}\n```"); + return Ok(RoomMessageEventContent::text_markdown(out)); + } + + let mut features = String::new(); + let enabled = info::rustc::features(); + let available = info::cargo::features(); + for feature in available { + let active = enabled.contains(&feature.as_str()); + let emoji = if active { + "✅" + } else { + "❌" + }; + let remark = if active { + "[enabled]" + } else { + "" + }; + writeln!(features, "{emoji} {feature} {remark}")?; + } + + Ok(RoomMessageEventContent::text_markdown(features)) +} + pub(super) async fn memory_usage(_body: Vec<&str>) -> Result { let services_usage = services().memory_usage().await?; let database_usage = services().db.db.memory_usage()?; diff --git a/src/admin/server/mod.rs b/src/admin/server/mod.rs index 604dacc7..958cc54b 100644 --- a/src/admin/server/mod.rs +++ b/src/admin/server/mod.rs @@ -14,6 +14,18 @@ pub(super) enum ServerCommand { /// - Show configuration values ShowConfig, + /// - List the features built into the server + ListFeatures { + #[arg(short, long)] + available: bool, + + #[arg(short, long)] + enabled: bool, + + #[arg(short, long)] + comma: bool, + }, + /// - Print database memory usage statistics MemoryUsage, @@ -54,6 +66,11 @@ pub(super) async fn process(command: ServerCommand, body: Vec<&str>) -> Result uptime(body).await?, ServerCommand::ShowConfig => show_config(body).await?, + ServerCommand::ListFeatures { + available, + enabled, + comma, + } => list_features(body, available, enabled, comma).await?, ServerCommand::MemoryUsage => memory_usage(body).await?, ServerCommand::ClearCaches => clear_caches(body).await?, ServerCommand::ListBackups => list_backups(body).await?,