add:remove functionality
This commit is contained in:
@@ -1,3 +1,6 @@
|
|||||||
|
# Main Repo is self-hosted on [GitHub](https://git.kokopi.dev/kokopi/scripts-organizer)
|
||||||
|
- This is a mirror
|
||||||
|
|
||||||
# Scripts Organizer
|
# Scripts Organizer
|
||||||
|
|
||||||
Helping organize your custom scripts in the `~/.local/bin` folder
|
Helping organize your custom scripts in the `~/.local/bin` folder
|
||||||
|
|||||||
@@ -1,6 +1,48 @@
|
|||||||
|
use cliclack::{confirm, note, outro, select};
|
||||||
|
|
||||||
use crate::{error::AppError, services::ServiceStore};
|
use crate::{error::AppError, services::ServiceStore};
|
||||||
|
|
||||||
pub fn run(_store: &ServiceStore) -> Result<(), AppError> {
|
pub fn run(store: &ServiceStore) -> Result<(), AppError> {
|
||||||
// TODO: load registry, prompt for selection, delete shim, update registry
|
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(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user