From c03635508b82e6f92ff54681eb469413b72ce461 Mon Sep 17 00:00:00 2001 From: Matt Mastracci Date: Thu, 31 Oct 2024 13:17:33 -0600 Subject: [PATCH] Hook up uninstall/list commands --- src/portable/extension.rs | 26 +++++++++++++++++++++++--- src/portable/options.rs | 2 -- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/src/portable/extension.rs b/src/portable/extension.rs index 89bc6060..a30fa967 100644 --- a/src/portable/extension.rs +++ b/src/portable/extension.rs @@ -55,7 +55,27 @@ fn get_local_instance(instance: &Option) -> Result Result<(), anyhow::Error> { let inst = get_local_instance(&options.instance)?; let extension_loader = inst.extension_loader_path()?; - run_extension_loader(&extension_loader, Some("--list"), None::<&str>)?; + let output = run_extension_loader(&extension_loader, Some("--list-packages"), None::<&str>)?; + let value: serde_json::Value = serde_json::from_str(&output)?; + + let mut table = Table::new(); + table.set_format(*table::FORMAT); + table.add_row(row!["Name", "Version"]); + if let Some(array) = value.as_array() { + for pkg in array { + let name = pkg + .get("extension_name") + .map(|s| s.as_str().unwrap_or_default().to_owned()) + .unwrap_or_default(); + let version = pkg + .get("extension_version") + .map(|s| s.as_str().unwrap_or_default().to_owned()) + .unwrap_or_default(); + table.add_row(row![name, version]); + } + } + table.printstd(); + Ok(()) } @@ -114,7 +134,7 @@ fn run_extension_loader( extension_installer: &Path, command: Option>, file: Option>, -) -> Result<(), anyhow::Error> { +) -> Result { let mut cmd = Command::new(extension_installer); if let Some(cmd_str) = command { @@ -141,7 +161,7 @@ fn run_extension_loader( trace!("STDERR:\n{}", String::from_utf8_lossy(&output.stderr)); } - Ok(()) + Ok(String::from_utf8_lossy(&output.stdout).to_string()) } fn list_extensions(options: &ExtensionListExtensions) -> Result<(), anyhow::Error> { diff --git a/src/portable/options.rs b/src/portable/options.rs index 580d71da..853ac428 100644 --- a/src/portable/options.rs +++ b/src/portable/options.rs @@ -90,14 +90,12 @@ pub struct ServerInstanceExtensionCommand { #[derive(clap::Subcommand, Clone, Debug)] pub enum InstanceExtensionCommand { /// List installed extensions for a local instance. - #[command(hide = true)] List(ExtensionList), /// List available extensions for a local instance. ListAvailable(ExtensionListExtensions), /// Install an extension for a local instance. Install(ExtensionInstall), /// Uninstall an extension from a local instance. - #[command(hide = true)] Uninstall(ExtensionUninstall), }