From 07a71e4650ba558a27444cfc358d562a914e6eaa Mon Sep 17 00:00:00 2001 From: kokopi-dev Date: Sat, 4 Apr 2026 23:09:51 +0900 Subject: [PATCH] add:remove functionality --- README.md | 3 +++ src/cli/remove.rs | 46 ++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 47 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 637d44e..0929e14 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/src/cli/remove.rs b/src/cli/remove.rs index 244e34d..30878a3 100644 --- a/src/cli/remove.rs +++ b/src/cli/remove.rs @@ -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(()) }