|
|
|
@ -1,8 +1,8 @@
|
|
|
|
|
mod db; |
|
|
|
|
mod storage; |
|
|
|
|
mod editor; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
use db::{DB, Item}; |
|
|
|
|
use storage::{Storage, Item}; |
|
|
|
|
|
|
|
|
|
use clap::{Parser, Subcommand}; |
|
|
|
|
use rpassword; |
|
|
|
@ -74,7 +74,7 @@ fn login() -> io::Result<String> {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
fn init() -> io::Result<()> { |
|
|
|
|
if db::DB::is_inited() { |
|
|
|
|
if Storage::is_inited() { |
|
|
|
|
return Err(io::Error::new(io::ErrorKind::AlreadyExists, "Reinitialization attempted")); |
|
|
|
|
} |
|
|
|
|
print!("Enter passphrase for storage: "); |
|
|
|
@ -89,15 +89,15 @@ fn init() -> io::Result<()> {
|
|
|
|
|
return Err(io::Error::new(io::ErrorKind::InvalidInput, "Passwords must be equal")); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
db::DB::init(password)?; |
|
|
|
|
Storage::init(password)?; |
|
|
|
|
|
|
|
|
|
Ok(()) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
fn add(id: &String) -> io::Result<()> { |
|
|
|
|
// TODO: get login passphrase
|
|
|
|
|
let mut db = DB::new(String::from(""))?; |
|
|
|
|
if db.contains(id) { |
|
|
|
|
let mut st = Storage::new(String::from(""))?; |
|
|
|
|
if st.contains(id) { |
|
|
|
|
// TODO: ask to edit existing in outer function which invoked this one
|
|
|
|
|
return Err(io::Error::new( |
|
|
|
|
io::ErrorKind::InvalidInput, |
|
|
|
@ -106,15 +106,16 @@ fn add(id: &String) -> io::Result<()> {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
let content = editor::open_to_edit()?; |
|
|
|
|
db.items.insert(Item::from(id.clone(), content)); |
|
|
|
|
db.dump()?; |
|
|
|
|
st.items.insert(Item::from(id.clone(), content)); |
|
|
|
|
st.dump()?; |
|
|
|
|
|
|
|
|
|
Ok(()) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
fn list() -> io:: Result<()> { |
|
|
|
|
let db = DB::new(String::from(""))?; |
|
|
|
|
let mut vec: Vec<_> = db.items.iter().collect(); |
|
|
|
|
// TODO: ask login
|
|
|
|
|
let st = Storage::new(String::from(""))?; |
|
|
|
|
let mut vec: Vec<_> = st.items.iter().collect(); |
|
|
|
|
vec.sort(); |
|
|
|
|
for item in &vec { |
|
|
|
|
println!("{}", item.id); |
|
|
|
@ -135,10 +136,10 @@ fn run_command() -> io::Result<()> {
|
|
|
|
|
list()?; |
|
|
|
|
} |
|
|
|
|
None => { |
|
|
|
|
if !db::DB::is_inited() { |
|
|
|
|
if !Storage::is_inited() { |
|
|
|
|
match get_prompt("Do you want to init your storage?")? { |
|
|
|
|
PROMPT::YES => init()?, |
|
|
|
|
PROMPT::NO => db::DB::print_init_hint(), |
|
|
|
|
PROMPT::NO => Storage::print_init_hint(), |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
login()?; |
|
|
|
|