//! Copyright (C) 2022, Dmitriy Pleshevskiy //! //! tas is free software: you can redistribute it and/or modify //! it under the terms of the GNU General Public License as published by //! the Free Software Foundation, either version 3 of the License, or //! (at your option) any later version. //! //! tas is distributed in the hope that it will be useful, //! but WITHOUT ANY WARRANTY; without even the implied warranty of //! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //! GNU General Public License for more details. //! //! You should have received a copy of the GNU General Public License //! along with tas. If not, see . //! use crate::domain::CurrentTaskInfo; use crate::repo::Repository; #[derive(clap::Args)] pub struct Args { #[clap(short, long)] finished: bool, projects: Vec, } pub fn execute(repo: impl Repository, args: Args) { let tasks = match repo.get_tasks(args.finished) { Ok(tasks) => tasks, Err(err) => return eprintln!("Cannot read tasks: {}", err), }; let cur_task = if args.finished { None } else { match repo.get_current_task_opt() { Ok(cur_task) => cur_task, Err(err) => { return eprintln!("Cannot read current task: {}", err); } } }; let projects = args .projects .into_iter() .map(|g| match g.as_str() { "-" => None, _ => Some(g), }) .collect::>(); let filtered_tasks = tasks .iter() .enumerate() .filter(|(_, t)| projects.is_empty() || projects.contains(&t.project)); for (i, task) in filtered_tasks { let idx = i + 1; match cur_task { Some(CurrentTaskInfo { task_idx, .. }) if task_idx == idx => print!("> "), _ => print!(" "), } print!("{}. ", idx); if let Some(project) = task.project.as_ref() { print!("[{}]: ", project); } print!("{}", task.name); if task.link.is_some() { print!(" (link)"); } println!(); } }