Skip to content

Commit

Permalink
Hook up uninstall/list commands (#1389)
Browse files Browse the repository at this point in the history
These are now supported in the extension loader, so we can hook them up to the CLI as well. These were previously hidden commands.
  • Loading branch information
mmastrac authored Nov 13, 2024
1 parent 5c93ab7 commit 7de43a2
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
26 changes: 23 additions & 3 deletions src/portable/extension.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,27 @@ fn get_local_instance(instance: &Option<InstanceName>) -> Result<InstanceInfo, a
fn list(options: &ExtensionList) -> 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(())
}

Expand Down Expand Up @@ -114,7 +134,7 @@ fn run_extension_loader(
extension_installer: &Path,
command: Option<impl AsRef<OsStr>>,
file: Option<impl AsRef<OsStr>>,
) -> Result<(), anyhow::Error> {
) -> Result<String, anyhow::Error> {
let mut cmd = Command::new(extension_installer);

if let Some(cmd_str) = command {
Expand All @@ -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> {
Expand Down
2 changes: 0 additions & 2 deletions src/portable/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
}

Expand Down

0 comments on commit 7de43a2

Please sign in to comment.