add:remove functionality
This commit is contained in:
@@ -1,6 +1,48 @@
|
||||
use cliclack::{confirm, note, outro, select};
|
||||
|
||||
use crate::{error::AppError, services::ServiceStore};
|
||||
|
||||
pub fn run(_store: &ServiceStore) -> Result<(), AppError> {
|
||||
// TODO: load registry, prompt for selection, delete shim, update registry
|
||||
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(())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user