|
|
|
@ -46,6 +46,11 @@ enum Commands {
|
|
|
|
|
Edit { |
|
|
|
|
#[arg(value_name="item_id")] |
|
|
|
|
id: String |
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
Delete { |
|
|
|
|
#[arg(value_name="item_id")] |
|
|
|
|
id: String |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
@ -157,6 +162,20 @@ impl MPS {
|
|
|
|
|
Ok(()) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
fn show(&mut self, id: &String) -> io::Result<()> { |
|
|
|
|
self.login()?; |
|
|
|
|
let st = self.storage.as_ref().unwrap(); |
|
|
|
|
if !st.contains(id) { |
|
|
|
|
return Err(io::Error::new( |
|
|
|
|
io::ErrorKind::InvalidInput, |
|
|
|
|
format!("Can`t find id: {}", id) |
|
|
|
|
)); |
|
|
|
|
} |
|
|
|
|
let item = st.get(id); |
|
|
|
|
editor::open_to_show(&item.content)?; |
|
|
|
|
Ok(()) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
fn add(&mut self, id: &String) -> io::Result<()> { |
|
|
|
|
self.login()?; |
|
|
|
|
let st = self.storage.as_mut().unwrap(); |
|
|
|
@ -190,29 +209,28 @@ impl MPS {
|
|
|
|
|
PROMPT::NO => return Ok(()) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
let mut item = (*st.get(id)).clone(); |
|
|
|
|
let new_content = editor::open_to_edit(&item.content)?; |
|
|
|
|
item.content = new_content; |
|
|
|
|
st.update(item); |
|
|
|
|
st.dump()?; |
|
|
|
|
|
|
|
|
|
Ok(()) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
fn show(&mut self, id: &String) -> io::Result<()> { |
|
|
|
|
fn delete(&mut self, id: &String) -> io::Result<()> { |
|
|
|
|
self.login()?; |
|
|
|
|
let st = self.storage.as_ref().unwrap(); |
|
|
|
|
let st = self.storage.as_mut().unwrap(); |
|
|
|
|
if !st.contains(id) { |
|
|
|
|
return Err(io::Error::new( |
|
|
|
|
io::ErrorKind::InvalidInput, |
|
|
|
|
format!("Can`t find id: {}", id) |
|
|
|
|
"No such item" |
|
|
|
|
)); |
|
|
|
|
} |
|
|
|
|
let item = st.get(id); |
|
|
|
|
editor::open_to_show(&item.content)?; |
|
|
|
|
st.remove(id); |
|
|
|
|
st.dump()?; |
|
|
|
|
Ok(()) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
fn run_command() -> io::Result<()> { |
|
|
|
@ -237,6 +255,10 @@ fn run_command() -> io::Result<()> {
|
|
|
|
|
let mut mps = MPS::new(); |
|
|
|
|
mps.edit(id)? |
|
|
|
|
} |
|
|
|
|
Some(Commands::Delete { id }) => { |
|
|
|
|
let mut mps = MPS::new(); |
|
|
|
|
mps.delete(id)? |
|
|
|
|
} |
|
|
|
|
None => { |
|
|
|
|
match Storage::check_installed() { |
|
|
|
|
Ok(()) => (), |
|
|
|
|