Add: last stamp (-l or --last) feature in stamps subcommand

main
Óscar M. Lage 2021-11-16 19:38:28 +01:00
parent dc96f2d423
commit 91b918a70e
3 changed files with 12 additions and 4 deletions

View File

@ -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")

View File

@ -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::<StampsResponse>().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),

View File

@ -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!!!"),