|
|
|
@ -90,18 +90,14 @@ fn init() -> io::Result<()> {
|
|
|
|
|
} |
|
|
|
|
print!("Enter passphrase for storage: "); |
|
|
|
|
io::stdout().flush()?; |
|
|
|
|
// TODO: rename to passphrase
|
|
|
|
|
let password = rpassword::read_password()?; |
|
|
|
|
let ps = rpassword::read_password()?; |
|
|
|
|
print!("Reenter passphrase: "); |
|
|
|
|
io::stdout().flush()?; |
|
|
|
|
let password2 = rpassword::read_password()?; |
|
|
|
|
|
|
|
|
|
if password != password2 { |
|
|
|
|
return Err(io::Error::new(io::ErrorKind::InvalidInput, "Passwords must be equal")); |
|
|
|
|
let ps2 = rpassword::read_password()?; |
|
|
|
|
if ps != ps2 { |
|
|
|
|
return Err(io::Error::new(io::ErrorKind::InvalidInput, "Passphrases must be equal")); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
Storage::init(password)?; |
|
|
|
|
|
|
|
|
|
Storage::init(ps)?; |
|
|
|
|
Ok(()) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -128,7 +124,6 @@ fn add(id: &String) -> io::Result<()> {
|
|
|
|
|
PROMPT::NO => return Ok(()), |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// set empty string because there is no content yet
|
|
|
|
|
let content = editor::open_to_edit(&String::from(""))?; |
|
|
|
|
st.add(Item::from(id.clone(), content)); |
|
|
|
@ -142,10 +137,14 @@ fn edit(id: &String) -> io::Result<()> {
|
|
|
|
|
let passphrase = login()?; |
|
|
|
|
let mut st = Storage::from_db(passphrase)?; |
|
|
|
|
if !st.contains(id) { |
|
|
|
|
return Err(io::Error::new( |
|
|
|
|
io::ErrorKind::InvalidInput, |
|
|
|
|
format!("Can`t find id: {}", id) |
|
|
|
|
)); |
|
|
|
|
let question = format!("Item [{}] exist. Do you want to add it instead?", id); |
|
|
|
|
match get_prompt(&question)? { |
|
|
|
|
PROMPT::YES => { |
|
|
|
|
add(id)?; |
|
|
|
|
return Ok(()); |
|
|
|
|
} |
|
|
|
|
PROMPT::NO => return Ok(()) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
let mut item = (*st.get(id)).clone(); |
|
|
|
@ -158,8 +157,9 @@ fn edit(id: &String) -> io::Result<()> {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn show(id: &String) -> io::Result<()> { |
|
|
|
|
let passphrase = login()?;
|
|
|
|
|
let mut st = Storage::from_db(passphrase)?; |
|
|
|
|
// TODO: get storage from login
|
|
|
|
|
let passphrase = login()?; |
|
|
|
|
let st = Storage::from_db(passphrase)?; |
|
|
|
|
if !st.contains(id) { |
|
|
|
|
return Err(io::Error::new( |
|
|
|
|
io::ErrorKind::InvalidInput, |
|
|
|
@ -168,7 +168,10 @@ fn show(id: &String) -> io::Result<()> {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
let item = st.get(id); |
|
|
|
|
editor::open_to_show(&item.content)?; |
|
|
|
|
//editor::open_to_show(&item.content)?;
|
|
|
|
|
println!("---------"); |
|
|
|
|
println!("{}", item.content); |
|
|
|
|
println!("---------"); |
|
|
|
|
Ok(()) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|