use clap;
use common::*;
use entry;
use lich::Error::Decrypt;
use std::fs::OpenOptions;
use std::path::PathBuf;
pub fn run(path: PathBuf) -> Result<(), clap::Error> {
let mut file = OpenOptions::new()
.read(true)
.write(true)
.open(&path)
.map_err(|e| read_error(&path, e))?;
let mut data = decode(&file, &path)?;
loop {
let (old, new) = entry::change_password();
match data.change_password(&old, &new) {
Ok(()) => break,
Err(e) =>
match e {
Decrypt => wlnerr!("Incorrect password; try again."),
e => return Err(read_error(&path, e))
}
}
}
save(&mut file, &path, &data)?;
println!("Updated the master password!");
Ok(())
}