tas/src/cli/list.rs

31 lines
821 B
Rust

use crate::domain::CurrentTaskInfo;
use crate::repo::Repository;
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);
}
};
for (i, task) in tasks.iter().enumerate() {
let idx = i + 1;
match cur_task {
Some(CurrentTaskInfo { task_idx, .. }) if task_idx == idx => print!("> "),
_ => print!(" "),
}
print!("{}. ", idx);
if task.link.is_some() {
print!("(link) ");
}
println!("{}", task.name);
}
}