diff --git a/src/main.rs b/src/main.rs index ac09438..292ab4e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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::>(); + 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);