diff --git a/src/cli.rs b/src/cli.rs index 105ad56..afc5b18 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -22,6 +22,14 @@ pub fn build_cli() -> App<'static, 'static> { .subcommand( SubCommand::with_name("stamps") .about("List last stamps") + .arg( + Arg::with_name("project") + .short("p") + .long("project") + .value_name("PROJECT") + .help("Provides a project to list stamps from") + .takes_value(true), + ) .arg( Arg::with_name("last") .short("l") diff --git a/src/main.rs b/src/main.rs index ea7bb64..a291cc8 100644 --- a/src/main.rs +++ b/src/main.rs @@ -55,18 +55,21 @@ fn main() { tasks.get(&config_file, project, last); } - // gst stamps [--last] + // gst stamps [--project] [--last] ("stamps", Some(_matches)) => { console::info("List of stamps"); let last = _matches.occurrences_of("last"); + let project = _matches.value_of("project") + .unwrap_or("0").trim().parse() + .expect("Type a number!"); let stamps = Stamps { data: Vec::new(), error: "".to_string(), }; - stamps.get(&config_file, last); + stamps.get(&config_file, project, last); } - // gst addtask [--project] "title" + // gst addtask --project NUM --title "title" --description "desc" ("addtask", Some(_matches)) => { console::info("Add a new task"); let project: u32 = _matches.value_of("project") diff --git a/src/models/stamps.rs b/src/models/stamps.rs index 6944a5e..a94262b 100644 --- a/src/models/stamps.rs +++ b/src/models/stamps.rs @@ -20,7 +20,7 @@ pub struct Stamps { } impl Stamps { - pub fn get(&self, config_file: &PathBuf, last: u64) { + pub fn get(&self, config_file: &PathBuf, project: u32, last: u64) { // Config let mut default_config = config::Config::default(); let config = default_config.parse(&config_file); @@ -39,10 +39,23 @@ impl Stamps { let stamps = parsed.json::().unwrap(); // eprintln!("{:#?}", stamps); for stamp in stamps.data { - println!("⏳ ({id}) {description}", - id=stamp.id, - description=stamp.description.unwrap()); - if last != 0 { break; } + match project { + 0 => { + println!("⏳ ({id}) {description}", + id=stamp.id, + description=stamp.description.unwrap()); + if last != 0 { break; } + }, + + _ => { + if project == stamp.project_id { + println!("⏳ ({id}) {description}", + id=stamp.id, + description=stamp.description.unwrap()); + if last != 0 { break; } + } + } + } } } Err(e) => println!("Error happened: {}", e),