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-16 15:43:44 +03:00
|
|
|
pub fn execute(repo: impl Repository) {
|
|
|
|
let tasks = match repo.get_tasks() {
|
|
|
|
Ok(tasks) => tasks,
|
|
|
|
Err(err) => return eprintln!("Cannot read tasks: {}", err),
|
|
|
|
};
|
|
|
|
|
|
|
|
let cur_task = match repo.get_current_task_opt() {
|
|
|
|
Ok(cur_task) => cur_task,
|
|
|
|
Err(err) => {
|
|
|
|
return eprintln!("Cannot read current task: {}", err);
|
|
|
|
}
|
|
|
|
};
|
2022-08-05 18:25:01 +03:00
|
|
|
|
2022-08-16 15:43:44 +03:00
|
|
|
for (i, task) in tasks.iter().enumerate() {
|
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-16 16:36:53 +03:00
|
|
|
if let Some(group) = task.group.as_ref() {
|
|
|
|
print!("[{}]: ", group);
|
|
|
|
}
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|