Skip to content

Commit

Permalink
Todo dependency is a class of its own now
Browse files Browse the repository at this point in the history
  • Loading branch information
nimaaskarian committed Jan 31, 2024
1 parent 30be459 commit d367a28
Show file tree
Hide file tree
Showing 5 changed files with 279 additions and 162 deletions.
4 changes: 3 additions & 1 deletion src/cli/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@ impl App {
println!("{}", todo.display(Some(show_done)));
let mut was_last_clone = was_last.clone();
was_last_clone.push(is_last);
Self::print_tree(&todo.dependencies, show_done, depth+1, was_last_clone);
if let Some(todo_list) = todo.dependency.todo_list() {
Self::print_tree(&todo_list, show_done, depth+1, was_last_clone);
}
}
}

Expand Down
11 changes: 5 additions & 6 deletions src/todo_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ impl TodoList {
let mut todos = [&mut self.undone.todos, &mut self.done.todos];

for todo in todos.iter_mut().flat_map(|v| v.iter_mut()) {
todo.read_dependencies(&path);
todo.dependency.read(&path);
}
}

Expand All @@ -275,9 +275,8 @@ impl TodoList {
let mut todos = [&mut self.undone.todos, &mut self.done.todos];

for todo in todos.iter_mut().flat_map(|v| v.iter_mut()) {
if let Some(todo_path) = todo.dependency_path(path) {
output.push(todo_path);
todo.dependencies.all_dependent_files(path, output);
if todo.dependency.is_list() {
todo.dependency.todo_list.all_dependent_files(path, output);
}
}

Expand Down Expand Up @@ -337,7 +336,7 @@ impl TodoList {
fn handle_dependent_files(&mut self, path: &PathBuf) -> io::Result<()> {
let mut todos = [&mut self.undone.todos, &mut self.done.todos];
for todo in todos.iter_mut().flat_map(|v| v.iter_mut()) {
todo.dependency_write(path)?;
todo.dependency.write(path)?;
todo.remove_dependent_files(path)?;
}
Ok(())
Expand Down Expand Up @@ -450,7 +449,7 @@ mod tests {
let mut todo_list = get_todo_list();
todo_list[0].add_todo_dependency();
let path = PathBuf::from("tests/tmplist");
todo_list[0].dependencies.push(Todo::try_from("[0] Some dependency").unwrap());
todo_list[0].dependency.push(Todo::try_from("[0] Some dependency").unwrap());
todo_list.write(&path, true);

let todo_dependency_path = PathBuf::from(format!("tests/notes/{}.todo", todo_list[0].hash()));
Expand Down
Loading

0 comments on commit d367a28

Please sign in to comment.