|
|
@ -24,16 +24,21 @@ enum Commands { |
|
|
|
/// Initialization of storage and config, use this in first time of usage of mps
|
|
|
|
/// Initialization of storage and config, use this in first time of usage of mps
|
|
|
|
Init, |
|
|
|
Init, |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// Lists all ids stored in db
|
|
|
|
|
|
|
|
List, |
|
|
|
|
|
|
|
|
|
|
|
/// Adds new item with unique id to the db
|
|
|
|
/// Adds new item with unique id to the db
|
|
|
|
Add { |
|
|
|
Add { |
|
|
|
#[arg(value_name="item_id")] |
|
|
|
#[arg(value_name="item_id")] |
|
|
|
id: String |
|
|
|
id: String |
|
|
|
}, |
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
/// Lists all ids stored in db
|
|
|
|
/// Show content of item
|
|
|
|
List |
|
|
|
Show { |
|
|
|
|
|
|
|
#[arg(value_name="item_id")] |
|
|
|
|
|
|
|
id: String |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// TODO: show
|
|
|
|
|
|
|
|
// TODO: edit
|
|
|
|
// TODO: edit
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
@ -94,6 +99,17 @@ fn init() -> io::Result<()> { |
|
|
|
Ok(()) |
|
|
|
Ok(()) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fn list() -> io:: Result<()> { |
|
|
|
|
|
|
|
let passphrase = login()?; |
|
|
|
|
|
|
|
let st = Storage::from_db(passphrase)?; |
|
|
|
|
|
|
|
let mut vec: Vec<_> = st.items.iter().collect(); |
|
|
|
|
|
|
|
vec.sort(); |
|
|
|
|
|
|
|
for item in &vec { |
|
|
|
|
|
|
|
println!("{}", item.id); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
Ok(()) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
fn add(id: &String) -> io::Result<()> { |
|
|
|
fn add(id: &String) -> io::Result<()> { |
|
|
|
let passphrase = login()?; |
|
|
|
let passphrase = login()?; |
|
|
|
let mut st = Storage::from_db(passphrase)?; |
|
|
|
let mut st = Storage::from_db(passphrase)?; |
|
|
@ -102,6 +118,7 @@ fn add(id: &String) -> io::Result<()> { |
|
|
|
return Err(io::Error::new( |
|
|
|
return Err(io::Error::new( |
|
|
|
io::ErrorKind::InvalidInput, |
|
|
|
io::ErrorKind::InvalidInput, |
|
|
|
format!("Dublicate item id: {}. Item id's must be unique.", id) |
|
|
|
format!("Dublicate item id: {}. Item id's must be unique.", id) |
|
|
|
|
|
|
|
// TODO: ask to edit [Y/n]
|
|
|
|
)) |
|
|
|
)) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -112,14 +129,19 @@ fn add(id: &String) -> io::Result<()> { |
|
|
|
Ok(()) |
|
|
|
Ok(()) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
fn list() -> io:: Result<()> { |
|
|
|
fn show(id: &String) -> io::Result<()> { |
|
|
|
let passphrase = login()?;
|
|
|
|
let passphrase = login()?;
|
|
|
|
let st = Storage::from_db(passphrase)?; |
|
|
|
let mut st = Storage::from_db(passphrase)?; |
|
|
|
let mut vec: Vec<_> = st.items.iter().collect(); |
|
|
|
if !st.contains(id) { |
|
|
|
vec.sort(); |
|
|
|
return Err(io::Error::new( |
|
|
|
for item in &vec { |
|
|
|
io::ErrorKind::InvalidInput, |
|
|
|
println!("{}", item.id); |
|
|
|
format!("Can`t find id: {}", id) |
|
|
|
|
|
|
|
)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let item = st.get(id); |
|
|
|
|
|
|
|
println!("content:"); |
|
|
|
|
|
|
|
println!("{}", item.content); |
|
|
|
Ok(()) |
|
|
|
Ok(()) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -132,6 +154,9 @@ fn run_command() -> io::Result<()> { |
|
|
|
Some(Commands::Add{ id }) => { |
|
|
|
Some(Commands::Add{ id }) => { |
|
|
|
add(id)?; |
|
|
|
add(id)?; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
Some(Commands::Show{ id }) => { |
|
|
|
|
|
|
|
show(id)?; |
|
|
|
|
|
|
|
} |
|
|
|
Some(Commands::List) => { |
|
|
|
Some(Commands::List) => { |
|
|
|
list()?; |
|
|
|
list()?; |
|
|
|
} |
|
|
|
} |
|
|
|