|
|
@ -46,7 +46,10 @@ enum Commands { |
|
|
|
Edit(ItemIdArgs), |
|
|
|
Edit(ItemIdArgs), |
|
|
|
|
|
|
|
|
|
|
|
/// Delete item
|
|
|
|
/// Delete item
|
|
|
|
Delete(ItemIdArgs) |
|
|
|
Delete(ItemIdArgs), |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// Set new passphrase
|
|
|
|
|
|
|
|
Password |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -121,10 +124,7 @@ impl MPS { |
|
|
|
Ok(ps) |
|
|
|
Ok(ps) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
fn init() -> io::Result<()> { |
|
|
|
fn read_new_password() -> io::Result<String> { |
|
|
|
if Storage::is_inited()? { |
|
|
|
|
|
|
|
return Err(io::Error::new(io::ErrorKind::AlreadyExists, "Reinitialization attempted")); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
let passphrase; |
|
|
|
let passphrase; |
|
|
|
loop { |
|
|
|
loop { |
|
|
|
match MPS::prompt_new_password() { |
|
|
|
match MPS::prompt_new_password() { |
|
|
@ -138,8 +138,15 @@ impl MPS { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
Storage::init(passphrase)?; |
|
|
|
Ok(passphrase) |
|
|
|
Ok(()) |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fn init() -> io::Result<()> { |
|
|
|
|
|
|
|
if Storage::is_inited()? { |
|
|
|
|
|
|
|
return Err(io::Error::new(io::ErrorKind::AlreadyExists, "Reinitialization attempted")); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
let passphrase = MPS::read_new_password()?; |
|
|
|
|
|
|
|
Storage::init(passphrase) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
pub fn login(&mut self) -> io::Result<()> { |
|
|
|
pub fn login(&mut self) -> io::Result<()> { |
|
|
@ -156,6 +163,14 @@ impl MPS { |
|
|
|
Ok(()) |
|
|
|
Ok(()) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pub fn password(&mut self) -> io::Result<()> { |
|
|
|
|
|
|
|
self.login()?; |
|
|
|
|
|
|
|
let st = self.storage.as_ref().unwrap(); |
|
|
|
|
|
|
|
let passphrase = MPS::read_new_password()?; |
|
|
|
|
|
|
|
let new_st = st.new_from_passphrase(&passphrase); |
|
|
|
|
|
|
|
new_st.dump() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
fn list(&mut self) -> io:: Result<()> { |
|
|
|
fn list(&mut self) -> io:: Result<()> { |
|
|
|
self.login()?; |
|
|
|
self.login()?; |
|
|
|
let ids = self.storage.as_ref().unwrap().ids(); |
|
|
|
let ids = self.storage.as_ref().unwrap().ids(); |
|
|
@ -176,8 +191,7 @@ impl MPS { |
|
|
|
self.login()?; |
|
|
|
self.login()?; |
|
|
|
let st = self.storage.as_ref().unwrap(); |
|
|
|
let st = self.storage.as_ref().unwrap(); |
|
|
|
let item = st.get(id); |
|
|
|
let item = st.get(id); |
|
|
|
editor::open_to_show(&item.content)?; |
|
|
|
editor::open_to_show(&item.content) |
|
|
|
Ok(()) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
fn add(&mut self, id: &String) -> io::Result<()> { |
|
|
|
fn add(&mut self, id: &String) -> io::Result<()> { |
|
|
@ -196,8 +210,7 @@ impl MPS { |
|
|
|
// set empty string because there is no content yet
|
|
|
|
// set empty string because there is no content yet
|
|
|
|
let content = editor::open_to_edit(&String::from(""))?; |
|
|
|
let content = editor::open_to_edit(&String::from(""))?; |
|
|
|
st.add(Item::from(id.clone(), content)); |
|
|
|
st.add(Item::from(id.clone(), content)); |
|
|
|
st.dump()?; |
|
|
|
st.dump() |
|
|
|
Ok(()) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/// Edit item, id need not to exist
|
|
|
|
/// Edit item, id need not to exist
|
|
|
@ -218,8 +231,7 @@ impl MPS { |
|
|
|
let new_content = editor::open_to_edit(&item.content)?; |
|
|
|
let new_content = editor::open_to_edit(&item.content)?; |
|
|
|
item.content = new_content; |
|
|
|
item.content = new_content; |
|
|
|
st.update(item); |
|
|
|
st.update(item); |
|
|
|
st.dump()?; |
|
|
|
st.dump() |
|
|
|
Ok(()) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Delete item by id, is must exist
|
|
|
|
// Delete item by id, is must exist
|
|
|
@ -227,8 +239,7 @@ impl MPS { |
|
|
|
self.login()?; |
|
|
|
self.login()?; |
|
|
|
let st = self.storage.as_mut().unwrap(); |
|
|
|
let st = self.storage.as_mut().unwrap(); |
|
|
|
st.remove(id); |
|
|
|
st.remove(id); |
|
|
|
st.dump()?; |
|
|
|
st.dump() |
|
|
|
Ok(()) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/// Resolve id by ItemArgs.
|
|
|
|
/// Resolve id by ItemArgs.
|
|
|
@ -292,6 +303,10 @@ fn run_command() -> io::Result<()> { |
|
|
|
let id = mps.item_id_by_item_id_args(args, true)?; |
|
|
|
let id = mps.item_id_by_item_id_args(args, true)?; |
|
|
|
mps.delete(&id)?; |
|
|
|
mps.delete(&id)?; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
Some(Commands::Password) => { |
|
|
|
|
|
|
|
let mut mps = MPS::new(); |
|
|
|
|
|
|
|
mps.password()?; |
|
|
|
|
|
|
|
} |
|
|
|
None => { |
|
|
|
None => { |
|
|
|
match Storage::check_installed() { |
|
|
|
match Storage::check_installed() { |
|
|
|
Ok(()) => (), |
|
|
|
Ok(()) => (), |
|
|
|