add dump command

master
Tom Alexander 5 years ago
parent 121f3bb9cd
commit a9b3c14b47

@ -22,6 +22,7 @@ Usage:
foil get [--db=<db>] foil get [--db=<db>]
foil list [--db=<db>] foil list [--db=<db>]
foil transfer [--db=<db>] foil transfer [--db=<db>]
foil dump [--db=<db>]
foil generate <spec> foil generate <spec>
foil (-h | --help) foil (-h | --help)
@ -38,6 +39,7 @@ struct Args {
cmd_list: bool, cmd_list: bool,
cmd_generate: bool, cmd_generate: bool,
cmd_transfer: bool, cmd_transfer: bool,
cmd_dump: bool,
flag_db: Option<String>, flag_db: Option<String>,
arg_spec: Option<String>, arg_spec: Option<String>,
} }
@ -142,6 +144,16 @@ fn set(mut db_conn: db::DbHandle, master_key: [u8; 32]) {
println!("Successfully added password"); println!("Successfully added password");
} }
fn dump(mut db_conn: db::DbHandle, master_key: [u8; 32]) {
for note in db_conn.read_notes(master_key).unwrap() {
println!("===== note =====");
println!("namespace: {}", note.namespace);
println!("category: {}", note.category);
println!("title: {}", note.title);
println!("{}", note.value);
}
}
fn transfer(mut db_conn: db::DbHandle, master_key: [u8; 32]) { fn transfer(mut db_conn: db::DbHandle, master_key: [u8; 32]) {
for account in db_conn.list_accounts(master_key).into_iter() { for account in db_conn.list_accounts(master_key).into_iter() {
let new_note = db::Note { let new_note = db::Note {
@ -150,7 +162,7 @@ fn transfer(mut db_conn: db::DbHandle, master_key: [u8; 32]) {
category: "account".to_owned(), category: "account".to_owned(),
title: account.host, title: account.host,
value: format!( value: format!(
"username: {}\npassword:{}\n", "username: {}\npassword: {}\n",
account.user, account.password account.user, account.password
), ),
}; };
@ -182,6 +194,8 @@ fn main() -> Result<(), Box<dyn Error>> {
list(db_conn, master_key); list(db_conn, master_key);
} else if args.cmd_transfer { } else if args.cmd_transfer {
transfer(db_conn, master_key); transfer(db_conn, master_key);
} else if args.cmd_dump {
dump(db_conn, master_key);
} }
Ok(()) Ok(())

Loading…
Cancel
Save