Skip to content
Open
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
6 changes: 6 additions & 0 deletions crates/mofa-cli/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,12 @@ pub enum PluginRepositoryCommands {
#[arg(short, long)]
description: Option<String>,
},

/// Remove a plugin repository
Remove {
/// Repository identifier
id: String,
},
}

/// Session management subcommands
Expand Down
47 changes: 47 additions & 0 deletions crates/mofa-cli/src/commands/plugin/repository.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,21 @@ pub async fn add(
Ok(())
}

/// Remove a plugin repository
pub async fn remove(ctx: &CliContext, id: &str) -> Result<(), CliError> {
let removed = ctx.plugin_repo_store.delete(id)?;

if removed {
println!("{} Repository '{}' removed", "✓".green(), id);
Ok(())
} else {
Err(CliError::PluginError(format!(
"Repository '{}' not found",
id
)))
}
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down Expand Up @@ -99,4 +114,36 @@ mod tests {
assert_eq!(stored.url, "https://example.org/plugins");
assert!(stored.last_synced.is_some());
}

#[tokio::test]
async fn remove_deletes_existing_repository() {
let temp = TempDir::new().unwrap();
let ctx = CliContext::with_temp_dir(temp.path()).await.unwrap();

add(
&ctx,
"custom",
"https://example.org/plugins",
Some("Example repo"),
)
.await
.unwrap();

remove(&ctx, "custom").await.unwrap();
assert!(ctx.plugin_repo_store.get("custom").unwrap().is_none());
}

#[tokio::test]
async fn remove_returns_error_for_missing_repository() {
let temp = TempDir::new().unwrap();
let ctx = CliContext::with_temp_dir(temp.path()).await.unwrap();

let err = remove(&ctx, "missing").await.unwrap_err();
match err {
CliError::PluginError(message) => {
assert!(message.contains("not found"));
}
other => panic!("Unexpected error type: {}", other),
}
}
}
3 changes: 3 additions & 0 deletions crates/mofa-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,9 @@ async fn run_command(cli: Cli) -> CliResult<()> {
commands::plugin::repository::add(ctx, &id, &url, description.as_deref())
.await?;
}
cli::PluginRepositoryCommands::Remove { id } => {
commands::plugin::repository::remove(ctx, &id).await?;
}
},
}
}
Expand Down
Loading