better input handling & argv handling

This commit is contained in:
Emma Tebibyte 2023-12-02 00:12:15 -07:00
parent e972bad2b7
commit 2006d9359b
Signed by: emma
GPG Key ID: 06FA419A1698C270

View File

@ -28,11 +28,16 @@ use keepass::{
DatabaseKey,
};
use yacexits::{ EX_UNAVAILABLE, EX_TEMPFAIL, exit};
use yacexits::{ EX_TEMPFAIL, EX_UNAVAILABLE, EX_USAGE, exit };
fn main() {
let argv = env::args().collect::<Vec<String>>();
if !argv.get(1).is_some() {
eprintln!("Usage: {} database", argv[0]);
exit(EX_USAGE);
}
let mut file = match File::open(&argv[1]) {
Ok(file) => file,
Err(err) => {
@ -47,9 +52,9 @@ fn main() {
exit(EX_UNAVAILABLE);
});
password.pop();
let password = password.lines().nth(0).unwrap_or(&"");
let key = DatabaseKey::new().with_password(&password);
let key = DatabaseKey::new().with_password(password);
let db = Database::open(&mut file, key).unwrap_or_else(|_| {
eprintln!("{}: Incorrect key.", argv[0]);
exit(EX_TEMPFAIL);