tas/src/cli/list.rs

32 lines
821 B
Rust
Raw Normal View History

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);
if task.link.is_some() {
print!("(link) ");
}
println!("{}", task.name);
}
}