smart-password-manager-cli 0.1.0

Command line interface for smart password management built on smartpasslib. Generate deterministic passwords from secret phrases without storing them.
use anyhow::{Result, bail};
use smartpasslib::SmartPasswordManager;

use crate::output;

use super::{find_entry, short_key};

pub fn run(
    key: Option<String>,
    description: Option<String>,
    new_description: Option<String>,
    new_length: Option<usize>,
) -> Result<()> {
    let mut manager = SmartPasswordManager::new()?;
    let entry = find_entry(&manager, key, description)?;

    if new_description.is_none() && new_length.is_none() {
        bail!("Provide --new-description and/or --new-length");
    }

    if let Some(len) = new_length {
        if len < 12 || len > 100 {
            bail!("Length must be between 12 and 100");
        }
    }

    if let Some(d) = &new_description {
        if d.trim().is_empty() {
            bail!("New description cannot be empty");
        }
    }

    let ok = manager.update(&entry.public_key, new_description.as_deref(), new_length)?;

    if ok {
        output::success(&format!(
            "Updated entry '{}' ({})",
            new_description.as_deref().unwrap_or(&entry.description),
            short_key(&entry.public_key)
        ));
    } else {
        output::error("Entry not found");
    }

    Ok(())
}