#![cfg(feature = "cli")]
use super::download::download_addon;
use super::metadata::get_addon_from_api;
use super::utils::extract_addon_archive;
use anyhow::{Context, Result};
pub async fn install_addon(slug: String, local: bool, _no_clear_tmp: bool) -> Result<()> {
if local {
install_local_addon(&slug).await
} else {
let addon_metadata = get_addon_from_api(&slug).await?;
download_addon(&slug, &addon_metadata).await?;
Ok(())
}
}
async fn install_local_addon(slug: &str) -> Result<()> {
let deva_dir = crate::tools::cli::config::path::ensure_deva_dir()?;
let archive_name = if slug.ends_with(".tar.gz") {
slug.to_string()
} else {
format!("{}.tar.gz", slug)
};
let archive_path = deva_dir.join(&archive_name);
if !archive_path.exists() {
return Err(anyhow::anyhow!(
"Local addon archive not found: {}\nTry running 'devalang addon discover --local' to see available local addons.",
archive_path.display()
));
}
extract_addon_archive(&archive_path, &deva_dir)
.context("Failed to extract local addon archive")?;
Ok(())
}