Add: --last (or -l) to tasks list for listing only last task

This commit is contained in:
Óscar M. Lage 2021-11-18 11:20:15 +01:00
parent effdbb778a
commit 0e8e12b453
3 changed files with 12 additions and 3 deletions

View File

@ -39,6 +39,12 @@ pub fn build_cli() -> App<'static, 'static> {
.value_name("PROJECT") .value_name("PROJECT")
.help("Provides a project to list tasks from") .help("Provides a project to list tasks from")
.takes_value(true), .takes_value(true),
)
.arg(
Arg::with_name("last")
.short("l")
.long("last")
.help("List last task only")
), ),
) )
.subcommand( .subcommand(

View File

@ -41,9 +41,10 @@ fn main() {
projects.get(&config_file); projects.get(&config_file);
} }
// gst tasks [--project] // gst tasks [--project] [--last]
("tasks", Some(_matches)) => { ("tasks", Some(_matches)) => {
console::info("List of tasks"); console::info("List of tasks");
let last = _matches.occurrences_of("last");
let project = _matches.value_of("project") let project = _matches.value_of("project")
.unwrap_or("0").trim().parse() .unwrap_or("0").trim().parse()
.expect("Type a number!"); .expect("Type a number!");
@ -51,7 +52,7 @@ fn main() {
data: Vec::new(), data: Vec::new(),
error: "".to_string(), error: "".to_string(),
}; };
tasks.get(&config_file, project); tasks.get(&config_file, project, last);
} }
// gst stamps [--last] // gst stamps [--last]

View File

@ -40,7 +40,7 @@ pub struct Tasks {
} }
impl Tasks { impl Tasks {
pub fn get(&self, config_file: &PathBuf, project: u32) { pub fn get(&self, config_file: &PathBuf, project: u32, last: u64) {
// Config // Config
let mut default_config = config::Config::default(); let mut default_config = config::Config::default();
let config = default_config.parse(&config_file); let config = default_config.parse(&config_file);
@ -65,6 +65,7 @@ impl Tasks {
projectid=task.project_id, projectid=task.project_id,
id=task.id, id=task.id,
name=task.name); name=task.name);
if last != 0 { break; }
}, },
// Otherwise but 0, print only task with that project.id // Otherwise but 0, print only task with that project.id
_ => { _ => {
@ -73,6 +74,7 @@ impl Tasks {
projectid=task.project_id, projectid=task.project_id,
id=task.id, id=task.id,
name=task.name); name=task.name);
if last != 0 { break; }
} }
} }
} }