49 lines
1.7 KiB
Rust
49 lines
1.7 KiB
Rust
use cliclack::{confirm, note, outro, select};
|
|
|
|
use crate::{error::AppError, services::ServiceStore};
|
|
|
|
pub fn run(store: &ServiceStore) -> Result<(), AppError> {
|
|
let registry = store.registry.load()?;
|
|
|
|
if registry.scripts.is_empty() {
|
|
note(
|
|
"No scripts registered",
|
|
"Use 'Add' to register your first script.",
|
|
)?;
|
|
return Ok(());
|
|
}
|
|
|
|
// ── Script selection ───────────────────────────────────────────────────────
|
|
let selected_name: String = {
|
|
let mut prompt = select("Which script would you like to remove?");
|
|
for entry in ®istry.scripts {
|
|
prompt = prompt.item(entry.name.clone(), &entry.name, &entry.description);
|
|
}
|
|
prompt.interact()?
|
|
};
|
|
|
|
let entry = registry
|
|
.scripts
|
|
.iter()
|
|
.find(|e| e.name == selected_name)
|
|
.expect("selected name must exist in registry");
|
|
|
|
// ── Confirm ────────────────────────────────────────────────────────────────
|
|
let confirmed = confirm(format!(
|
|
"Remove '{}'? This will delete the shim and symlink.",
|
|
entry.name
|
|
))
|
|
.interact()?;
|
|
|
|
if !confirmed {
|
|
return Err(AppError::Cancelled);
|
|
}
|
|
|
|
// ── Remove ─────────────────────────────────────────────────────────────────
|
|
store.registry.remove(&entry.name)?;
|
|
|
|
outro(format!("'{}' removed.", selected_name))?;
|
|
|
|
Ok(())
|
|
}
|