From 3d4d657f87bb8c2efeb7f9645ee30e7e8c7d0e2f Mon Sep 17 00:00:00 2001 From: Coin de Gamma Date: Tue, 17 Sep 2024 16:04:31 +0000 Subject: [PATCH] edit on add existing --- src/main.rs | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/main.rs b/src/main.rs index 46c346d..83e8fb9 100644 --- a/src/main.rs +++ b/src/main.rs @@ -119,12 +119,14 @@ fn add(id: &String) -> io::Result<()> { let passphrase = login()?; let mut st = Storage::from_db(passphrase)?; if st.contains(id) { - // TODO: ask to edit existing in outer function which invoked this one - return Err(io::Error::new( - io::ErrorKind::InvalidInput, - format!("Dublicate item id: {}. Item id's must be unique.", id) - // TODO: ask to edit [Y/n] - )) + let question = format!("Item [{}] exist. Do you want to edit it instead?", id); + match get_prompt(&question)? { + PROMPT::YES => { + edit(id)?; + return Ok(()); + }, + PROMPT::NO => return Ok(()), + } } let content = editor::open_to_edit()?;