Add: --project argument to "stamps" for listing stamps per project
This commit is contained in:
parent
0e8e12b453
commit
9f7d2648c4
@ -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")
|
||||
|
@ -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")
|
||||
|
@ -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,12 +39,25 @@ impl Stamps {
|
||||
let stamps = parsed.json::<Stamps>().unwrap();
|
||||
// eprintln!("{:#?}", stamps);
|
||||
for stamp in stamps.data {
|
||||
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),
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user