Add: --project argument to "stamps" for listing stamps per project

main
Óscar M. Lage 2021-11-18 11:57:32 +01:00
parent 0e8e12b453
commit 9f7d2648c4
3 changed files with 32 additions and 8 deletions

View File

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

View File

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

View File

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