add:edit functionality

This commit is contained in:
kokopi-dev
2026-04-05 00:15:48 +09:00
parent 2e00f08557
commit 9974b8eccd
4 changed files with 262 additions and 25 deletions

View File

@@ -2,7 +2,10 @@ use std::{os::unix::process::CommandExt, process::Command};
use cliclack::{confirm, log, note, outro, select};
use crate::{error::AppError, services::ServiceStore};
use crate::{
error::AppError,
services::{registry_service::is_healthy, ServiceStore},
};
/// Health of a registered script's files on disk.
#[derive(Clone, Eq, PartialEq)]
@@ -27,17 +30,12 @@ pub fn run(store: &ServiceStore) -> Result<(), AppError> {
.scripts
.iter()
.map(|entry| {
let health = if is_healthy(entry) {
Health::Ok
} else {
Health::Broken
};
let health = if is_healthy(entry) { Health::Ok } else { Health::Broken };
(entry, health)
})
.collect();
// ── Script selection ───────────────────────────────────────────────────────
// Use the script name as the select value — simple, Clone+Eq for free.
let selected_name: String = {
let mut prompt = select("Which script?");
for (entry, health) in &annotated {
@@ -50,7 +48,6 @@ pub fn run(store: &ServiceStore) -> Result<(), AppError> {
prompt.interact()?
};
// Look up the full entry and its health by name
let (entry, health) = annotated
.into_iter()
.find(|(e, _)| e.name == selected_name)
@@ -80,20 +77,3 @@ pub fn run(store: &ServiceStore) -> Result<(), AppError> {
// exec() only returns on failure
Err(AppError::Io(err))
}
/// Returns true if both the shim and the symlink target are present on disk.
fn is_healthy(entry: &crate::config::types::ScriptEntry) -> bool {
use std::os::unix::fs::PermissionsExt;
let shim_ok = entry
.shim_path
.metadata()
.map(|m| m.is_file() && m.permissions().mode() & 0o111 != 0)
.unwrap_or(false);
// Follow the symlink — if the target is gone, symlink_metadata succeeds but
// metadata() (which follows links) will fail
let symlink_ok = entry.symlink_path.metadata().map(|m| m.is_file()).unwrap_or(false);
shim_ok && symlink_ok
}