~gpanders/passage

ref: bfe9b097a356f0585b5380fbd40f58a280edd816 passage/src/cmd/remove.rs -rw-r--r-- 739 bytes
bfe9b097Gregory Anders Update output for remove command 9 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
use crate::error::Error;
use crate::input;
use crate::store::PasswordStore;

pub fn remove(store: PasswordStore, item: Option<&str>, force: bool) -> Result<(), Error> {
    let item = match item {
        Some(s) => s.to_string(),
        None => {
            input::read_input("Enter the name of the item you wish to remove from your store.\n>")?
        }
    };

    if !store.exists(&item) {
        return Err(Error::ItemNotFound(item));
    }

    if !force {
        let ans = input::read_input(&format!("Delete {}? [y/N]", item))?.to_lowercase();
        if ans != "y" && ans != "yes" {
            return Ok(());
        }
    }

    store.delete(&item)?;
    eprintln!("Removed {} from the password store.", item);
    Ok(())
}