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