2022-08-18 11:37:52 +03:00
|
|
|
//! Copyright (C) 2022, Dmitriy Pleshevskiy <dmitriy@ideascup.me>
|
|
|
|
//!
|
|
|
|
//! 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 <https://www.gnu.org/licenses/>.
|
|
|
|
//!
|
2022-08-16 15:43:44 +03:00
|
|
|
use crate::domain::CurrentTaskInfo;
|
|
|
|
use crate::repo::Repository;
|
2022-08-05 18:25:01 +03:00
|
|
|
|
2022-08-18 12:18:06 +03:00
|
|
|
#[derive(clap::Args)]
|
|
|
|
pub struct Args {
|
2022-08-20 23:38:38 +03:00
|
|
|
#[clap(short, long)]
|
|
|
|
finished: bool,
|
|
|
|
|
2022-08-18 14:10:20 +03:00
|
|
|
projects: Vec<String>,
|
2022-08-18 12:18:06 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn execute(repo: impl Repository, args: Args) {
|
2022-08-20 23:38:38 +03:00
|
|
|
let tasks = match repo.get_tasks(args.finished) {
|
2022-08-16 15:43:44 +03:00
|
|
|
Ok(tasks) => tasks,
|
|
|
|
Err(err) => return eprintln!("Cannot read tasks: {}", err),
|
|
|
|
};
|
|
|
|
|
2022-08-21 00:01:00 +03:00
|
|
|
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);
|
|
|
|
}
|
2022-08-16 15:43:44 +03:00
|
|
|
}
|
|
|
|
};
|
2022-08-05 18:25:01 +03:00
|
|
|
|
2022-08-18 14:10:20 +03:00
|
|
|
let projects = args
|
|
|
|
.projects
|
2022-08-18 12:18:06 +03:00
|
|
|
.into_iter()
|
|
|
|
.map(|g| match g.as_str() {
|
|
|
|
"-" => None,
|
|
|
|
_ => Some(g),
|
|
|
|
})
|
|
|
|
.collect::<Vec<_>>();
|
|
|
|
|
|
|
|
let filtered_tasks = tasks
|
|
|
|
.iter()
|
|
|
|
.enumerate()
|
2022-08-18 14:10:20 +03:00
|
|
|
.filter(|(_, t)| projects.is_empty() || projects.contains(&t.project));
|
2022-08-18 12:18:06 +03:00
|
|
|
|
|
|
|
for (i, task) in filtered_tasks {
|
2022-08-05 18:25:01 +03:00
|
|
|
let idx = i + 1;
|
|
|
|
|
2022-08-16 15:43:44 +03:00
|
|
|
match cur_task {
|
2022-08-05 18:25:01 +03:00
|
|
|
Some(CurrentTaskInfo { task_idx, .. }) if task_idx == idx => print!("> "),
|
|
|
|
_ => print!(" "),
|
|
|
|
}
|
|
|
|
|
|
|
|
print!("{}. ", idx);
|
2022-08-18 14:10:20 +03:00
|
|
|
if let Some(project) = task.project.as_ref() {
|
|
|
|
print!("[{}]: ", project);
|
2022-08-16 16:36:53 +03:00
|
|
|
}
|
|
|
|
print!("{}", task.name);
|
2022-08-05 18:25:01 +03:00
|
|
|
if task.link.is_some() {
|
2022-08-16 16:36:53 +03:00
|
|
|
print!(" (link)");
|
2022-08-05 18:25:01 +03:00
|
|
|
}
|
2022-08-16 16:36:53 +03:00
|
|
|
println!();
|
2022-08-05 18:25:01 +03:00
|
|
|
}
|
|
|
|
}
|