better input handling & argv handling
This commit is contained in:
parent
e972bad2b7
commit
2006d9359b
11
src/main.rs
11
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::<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);
|
||||
|
Loading…
Reference in New Issue
Block a user