feat(cli/org): interactive per-type org edit via shared edit helpers
This commit is contained in:
@@ -991,21 +991,9 @@ fn resolve_org_query<'a>(
|
||||
}
|
||||
}
|
||||
|
||||
pub fn run_edit(
|
||||
dir: &Path,
|
||||
query: &str,
|
||||
title: Option<String>,
|
||||
username: Option<String>,
|
||||
url: Option<String>,
|
||||
password: Option<String>,
|
||||
body: Option<String>,
|
||||
email: Option<String>,
|
||||
phone: Option<String>,
|
||||
full_name: Option<String>,
|
||||
) -> Result<()> {
|
||||
pub fn run_edit(dir: &Path, query: &str, totp_qr: Option<std::path::PathBuf>) -> Result<()> {
|
||||
use relicario_core::time::now_unix;
|
||||
use relicario_core::ItemCore;
|
||||
use zeroize::Zeroizing;
|
||||
|
||||
let vault = crate::org_session::open_org_vault(Some(dir))?;
|
||||
let caller = vault.current_member()?;
|
||||
@@ -1017,31 +1005,28 @@ pub fn run_edit(
|
||||
crate::org_session::UnlockedOrgVault::ensure_grant(&caller, &collection)?;
|
||||
|
||||
let mut item = vault.load_item(&collection, &id)?;
|
||||
eprintln!(
|
||||
"Editing: {} ({}) — leave a prompt blank to keep the current value.",
|
||||
item.title,
|
||||
item.id.as_str()
|
||||
);
|
||||
if let Some(v) = crate::prompt::prompt_keep("Title", &item.title)? {
|
||||
item.title = v;
|
||||
}
|
||||
|
||||
if let Some(t) = title { item.title = t; }
|
||||
|
||||
let history = &mut item.field_history;
|
||||
match &mut item.core {
|
||||
ItemCore::Login(l) => {
|
||||
if let Some(u) = username { l.username = Some(u); }
|
||||
if let Some(u) = url {
|
||||
l.url = Some(url::Url::parse(&u).with_context(|| format!("invalid URL: {u}"))?);
|
||||
}
|
||||
if let Some(p) = password { l.password = Some(Zeroizing::new(p)); }
|
||||
}
|
||||
ItemCore::SecureNote(n) => {
|
||||
if let Some(b) = body { n.body = Zeroizing::new(b); }
|
||||
}
|
||||
ItemCore::Identity(i) => {
|
||||
if let Some(v) = full_name { i.full_name = Some(v); }
|
||||
if let Some(v) = email { i.email = Some(v); }
|
||||
if let Some(v) = phone { i.phone = Some(v); }
|
||||
}
|
||||
_ => anyhow::bail!("org edit currently supports login, secure-note, and identity items"),
|
||||
ItemCore::Login(l) => ib::edit_login(l, history, totp_qr)?,
|
||||
ItemCore::SecureNote(n) => ib::edit_secure_note(n, history)?,
|
||||
ItemCore::Identity(i) => ib::edit_identity(i)?,
|
||||
ItemCore::Card(c) => ib::edit_card(c, history)?,
|
||||
ItemCore::Key(k) => ib::edit_key(k, history)?,
|
||||
ItemCore::Document(_) => ib::edit_document_message(),
|
||||
ItemCore::Totp(t) => ib::edit_totp(t, history)?,
|
||||
}
|
||||
|
||||
item.modified = now_unix();
|
||||
let item_rel = vault.save_item(&collection, &item)?;
|
||||
|
||||
let mut manifest = vault.load_manifest()?;
|
||||
upsert_org_entry(&mut manifest, &item, &collection);
|
||||
vault.save_manifest(&manifest)?;
|
||||
@@ -1053,12 +1038,14 @@ pub fn run_edit(
|
||||
);
|
||||
let commit_msg = format!(
|
||||
"{subject}\n\nRelicario-Actor: {} {}\nRelicario-Action: item-update\nRelicario-Collection: {}\nRelicario-Item: {}",
|
||||
caller.display_name, caller.member_id.as_str(), collection, item.id.as_str()
|
||||
caller.display_name,
|
||||
caller.member_id.as_str(),
|
||||
collection,
|
||||
item.id.as_str()
|
||||
);
|
||||
crate::org_session::org_git_run(&vault.root, &["add", &item_rel, "manifest.enc"], "org edit: git add")?;
|
||||
crate::org_session::org_git_run(&vault.root, &["commit", "-m", &commit_msg], "org edit: git commit")?;
|
||||
|
||||
println!("Updated {}", item.id.as_str());
|
||||
println!("Updated {} ({}) in `{}`", item.title, item.id.as_str(), collection);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user