add:remove functionality

This commit is contained in:
kokopi-dev
2026-04-04 23:09:51 +09:00
parent 36d2227a86
commit 07a71e4650
2 changed files with 47 additions and 2 deletions

View File

@@ -1,3 +1,6 @@
# Main Repo is self-hosted on [GitHub](https://git.kokopi.dev/kokopi/scripts-organizer)
- This is a mirror
# Scripts Organizer
Helping organize your custom scripts in the `~/.local/bin` folder

View File

@@ -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 &registry.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(())
}