diff --git a/src/cli.rs b/src/cli.rs index dd4c7fb..105ad56 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -39,6 +39,12 @@ pub fn build_cli() -> App<'static, 'static> { .value_name("PROJECT") .help("Provides a project to list tasks from") .takes_value(true), + ) + .arg( + Arg::with_name("last") + .short("l") + .long("last") + .help("List last task only") ), ) .subcommand( diff --git a/src/main.rs b/src/main.rs index 3b6a5f0..ea7bb64 100644 --- a/src/main.rs +++ b/src/main.rs @@ -41,9 +41,10 @@ fn main() { projects.get(&config_file); } - // gst tasks [--project] + // gst tasks [--project] [--last] ("tasks", Some(_matches)) => { console::info("List of tasks"); + let last = _matches.occurrences_of("last"); let project = _matches.value_of("project") .unwrap_or("0").trim().parse() .expect("Type a number!"); @@ -51,7 +52,7 @@ fn main() { data: Vec::new(), error: "".to_string(), }; - tasks.get(&config_file, project); + tasks.get(&config_file, project, last); } // gst stamps [--last] diff --git a/src/models/tasks.rs b/src/models/tasks.rs index c753e57..44ee254 100644 --- a/src/models/tasks.rs +++ b/src/models/tasks.rs @@ -40,7 +40,7 @@ pub struct Tasks { } impl Tasks { - pub fn get(&self, config_file: &PathBuf, project: u32) { + 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); @@ -65,6 +65,7 @@ impl Tasks { projectid=task.project_id, id=task.id, name=task.name); + if last != 0 { break; } }, // Otherwise but 0, print only task with that project.id _ => { @@ -73,6 +74,7 @@ impl Tasks { projectid=task.project_id, id=task.id, name=task.name); + if last != 0 { break; } } } }