Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hook up uninstall/list commands #1389

Merged
merged 1 commit into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading