add debug list-dependencies admin command

Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
Jason Volk 2024-07-25 21:29:37 +00:00
parent c423a83656
commit 271959ee27
3 changed files with 53 additions and 1 deletions

View file

@ -745,3 +745,27 @@ pub(super) async fn time(_body: &[&str]) -> Result<RoomMessageEventContent> {
let now = SystemTime::now();
Ok(RoomMessageEventContent::text_markdown(utils::time::format(now, "%+")))
}
pub(super) async fn list_dependencies(_body: &[&str], names: bool) -> Result<RoomMessageEventContent> {
if names {
let out = info::cargo::dependencies_names().join(" ");
return Ok(RoomMessageEventContent::notice_markdown(out));
}
let deps = info::cargo::dependencies();
let mut out = String::new();
writeln!(out, "| name | version | features |")?;
writeln!(out, "| ---- | ------- | -------- |")?;
for (name, dep) in deps {
let version = dep.try_req().unwrap_or("*");
let feats = dep.req_features();
let feats = if !feats.is_empty() {
feats.join(" ")
} else {
String::new()
};
writeln!(out, "{name} | {version} | {feats}")?;
}
Ok(RoomMessageEventContent::notice_markdown(out))
}

View file

@ -178,6 +178,12 @@ pub(super) enum DebugCommand {
/// - Print the current time
Time,
/// - List dependencies
ListDependencies {
#[arg(short, long)]
names: bool,
},
/// - Developer test stubs
#[command(subcommand)]
#[allow(non_snake_case)]

View file

@ -5,7 +5,7 @@
use std::sync::OnceLock;
use cargo_toml::Manifest;
use cargo_toml::{DepsSet, Manifest};
use conduit_macros::cargo_manifest;
use crate::Result;
@ -36,6 +36,18 @@ const MAIN_MANIFEST: &'static str = ();
/// For *enabled* features see the info::rustc module instead.
static FEATURES: OnceLock<Vec<String>> = OnceLock::new();
/// Processed list of dependencies. This is generated from the datas captured in
/// the MANIFEST.
static DEPENDENCIES: OnceLock<DepsSet> = OnceLock::new();
#[must_use]
pub fn dependencies_names() -> Vec<&'static str> { dependencies().keys().map(String::as_str).collect() }
pub fn dependencies() -> &'static DepsSet {
DEPENDENCIES
.get_or_init(|| init_dependencies().unwrap_or_else(|e| panic!("Failed to initialize dependencies: {e}")))
}
/// List of all possible features for the project. For *enabled* features in
/// this build see the companion function in info::rustc.
pub fn features() -> &'static Vec<String> {
@ -64,3 +76,13 @@ fn append_features(features: &mut Vec<String>, manifest: &str) -> Result<()> {
Ok(())
}
fn init_dependencies() -> Result<DepsSet> {
let manifest = Manifest::from_str(WORKSPACE_MANIFEST)?;
Ok(manifest
.workspace
.as_ref()
.expect("manifest has workspace section")
.dependencies
.clone())
}