Skip to content

Commit

Permalink
Add nicer format to pick. #ERABU-2 fixed
Browse files Browse the repository at this point in the history
Signed-off-by: SitiSchu <admin@sitischu.com>
  • Loading branch information
SitiSchu committed Aug 11, 2019
1 parent ae08bd6 commit 13238ec
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
4 changes: 3 additions & 1 deletion src/main.rs
Expand Up @@ -26,6 +26,8 @@ enum Opt {
Pick {
#[structopt(name = "collection", help = "The name of the collection")]
collection_name: String,
#[structopt(long = "no-format", help = "Don't format the output")]
no_format: bool,
},

#[structopt(name = "list", about = "List all collections or the items of a collection")]
Expand All @@ -40,7 +42,7 @@ fn main() -> Result<(), Box<std::error::Error>> {
match matches {
Opt::Add { collection_name, items } => subcommands::add::add_items(collection_name, items)?,
Opt::Del { collection_name, items } => subcommands::del::del_items(collection_name, items)?,
Opt::Pick { collection_name } => subcommands::pick::pick_item(collection_name)?,
Opt::Pick { collection_name, no_format } => subcommands::pick::pick_item(collection_name, no_format)?,
Opt::List { collection_name } => match collection_name {
Some(name) => subcommands::list::list_items(name)?,
None => subcommands::list::list_collections()?
Expand Down
11 changes: 9 additions & 2 deletions src/subcommands/pick.rs
@@ -1,7 +1,14 @@
use colored::Colorize;

use crate::collection::Collection;

pub fn pick_item(collection_name: String) -> Result<(), Box<std::error::Error>> {
pub fn pick_item(collection_name: String, no_format: bool) -> Result<(), Box<std::error::Error>> {
let collection = Collection::new(&collection_name)?;
println!("{}", collection.pick());
if no_format {
println!("{}", collection.pick());
} else {
println!("{} {}", "Picked item:".blue().bold(), collection.pick());
};

Ok(())
}

0 comments on commit 13238ec

Please sign in to comment.