From 91b918a70ed52dbc4962cfb12f0b92e43fbf763e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?O=CC=81scar=20M=2E=20Lage?= Date: Tue, 16 Nov 2021 19:38:28 +0100 Subject: [PATCH] Add: last stamp (-l or --last) feature in stamps subcommand --- src/cli.rs | 8 +++++++- src/cmd.rs | 5 +++-- src/main.rs | 3 ++- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/cli.rs b/src/cli.rs index eb55de5..473ee88 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -21,7 +21,13 @@ pub fn build_cli() -> App<'static, 'static> { ) .subcommand( SubCommand::with_name("stamps") - .about("List last stamps"), + .about("List last stamps") + .arg( + Arg::with_name("last") + .short("l") + .long("last") + .help("List last stamp only") + ), ) .subcommand( SubCommand::with_name("tasks") diff --git a/src/cmd.rs b/src/cmd.rs index 8e9449b..aa7abe3 100644 --- a/src/cmd.rs +++ b/src/cmd.rs @@ -115,17 +115,18 @@ pub fn get_tasks(config_file: &PathBuf, project: u32) { } } -pub fn get_stamps(config_file: &PathBuf) { +pub fn get_stamps(config_file: &PathBuf, last: u64) { let response = api_call(&config_file, String::from("stamps")); // eprintln!("{:#?}", response); match response { Ok(parsed) => { let stamps = parsed.json::().unwrap(); - eprintln!("{:#?}", stamps); + // eprintln!("{:#?}", stamps); for stamp in stamps.data { println!("⏳ ({id}) {description}", id=stamp.id, description=stamp.description.unwrap()); + if last != 0 { break; } } } Err(e) => println!("Error happened: {}", e), diff --git a/src/main.rs b/src/main.rs index 1394c85..ba70d75 100644 --- a/src/main.rs +++ b/src/main.rs @@ -38,7 +38,8 @@ fn main() { // gst stamps ("stamps", Some(_matches)) => { console::info("List of stamps"); - cmd::get_stamps(&config_file); + let last = _matches.occurrences_of("last"); + cmd::get_stamps(&config_file, last); } _ => console::error("Whut!!!"),