set command updated
This commit is contained in:
parent
b362561466
commit
cf15339712
33
src/main.rs
33
src/main.rs
@ -18,7 +18,7 @@ static USAGE: &'static str = "
|
|||||||
foil
|
foil
|
||||||
|
|
||||||
Usage:
|
Usage:
|
||||||
foil set [--db=<db>]
|
foil set [--namespace=<ns>] [--db=<db>]
|
||||||
foil get [--namespace=<ns>] [--db=<db>]
|
foil get [--namespace=<ns>] [--db=<db>]
|
||||||
foil list [--db=<db>]
|
foil list [--db=<db>]
|
||||||
foil transfer [--db=<db>]
|
foil transfer [--db=<db>]
|
||||||
@ -120,7 +120,7 @@ fn get(mut db_conn: db::DbHandle, master_key: [u8; 32], namespace: &str) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn set(mut db_conn: db::DbHandle, master_key: [u8; 32]) {
|
fn set(mut db_conn: db::DbHandle, master_key: [u8; 32], namespace: &str) {
|
||||||
println!("Adding a site to the database");
|
println!("Adding a site to the database");
|
||||||
let host: String = Input::with_theme(&ColorfulTheme::default())
|
let host: String = Input::with_theme(&ColorfulTheme::default())
|
||||||
.with_prompt("hostname")
|
.with_prompt("hostname")
|
||||||
@ -130,18 +130,21 @@ fn set(mut db_conn: db::DbHandle, master_key: [u8; 32]) {
|
|||||||
.with_prompt("username")
|
.with_prompt("username")
|
||||||
.interact()
|
.interact()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let encrypted_host: crypt::EncryptedValue = crypt::encrypt_value(&host, master_key);
|
let password: String = PasswordInput::with_theme(&ColorfulTheme::default())
|
||||||
let encrypted_username: crypt::EncryptedValue = crypt::encrypt_value(&username, master_key);
|
.with_prompt("Site password")
|
||||||
let encrypted_password: crypt::EncryptedValue = {
|
.with_confirmation("Repeat site password", "Error: the passwords don't match.")
|
||||||
let password: String = PasswordInput::with_theme(&ColorfulTheme::default())
|
.interact()
|
||||||
.with_prompt("Site password")
|
.unwrap();
|
||||||
.with_confirmation("Repeat site password", "Error: the passwords don't match.")
|
db_conn.write_note(
|
||||||
.interact()
|
master_key,
|
||||||
.unwrap();
|
db::Note {
|
||||||
crypt::encrypt_value(&password, master_key)
|
id: 0,
|
||||||
};
|
namespace: namespace.to_string(),
|
||||||
db_conn.delete_account_with_host(master_key, &host);
|
category: "account".to_string(),
|
||||||
let _account_id = db_conn.write_account(encrypted_host, encrypted_username, encrypted_password);
|
title: host,
|
||||||
|
value: format!("username: {}\npassword: {}\n", username, password),
|
||||||
|
},
|
||||||
|
);
|
||||||
println!("Successfully added password");
|
println!("Successfully added password");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -188,7 +191,7 @@ fn main() -> Result<(), Box<dyn Error>> {
|
|||||||
let master_key: [u8; 32] = get_master_key(&mut db_conn);
|
let master_key: [u8; 32] = get_master_key(&mut db_conn);
|
||||||
|
|
||||||
if args.cmd_set {
|
if args.cmd_set {
|
||||||
set(db_conn, master_key);
|
set(db_conn, master_key, &args.flag_namespace);
|
||||||
} else if args.cmd_get {
|
} else if args.cmd_get {
|
||||||
get(db_conn, master_key, &args.flag_namespace);
|
get(db_conn, master_key, &args.flag_namespace);
|
||||||
} else if args.cmd_list {
|
} else if args.cmd_list {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user