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