clean command

This commit is contained in:
aaron-jack-manning 2022-08-22 18:58:13 +10:00
parent f43d583ae6
commit 6aa3eb4e83
3 changed files with 19 additions and 1 deletions

View File

@ -44,4 +44,3 @@ Run `--help` alongside any command to get details on what it does.
- Due dates
- Taken as input when creating notes
- Displayed in list view by default (with number of days remaining)
- `clean` command to delete discarded tasks

View File

@ -48,6 +48,8 @@ enum Command {
Delete {
id_or_name : String,
},
/// Deletes all discarded tasks.
Clean,
/// Discard a task without deleting the underlying file.
Discard {
id_or_name : String,
@ -242,6 +244,10 @@ fn program() -> Result<(), error::Error> {
List {} => {
tasks::list(vault_folder)?;
},
Clean => {
tasks::clean(vault_folder)?;
println!("Deleted all discarded tasks");
}
// All commands which are dealt with in if let chain at start.
Vault(_) | Config(_) | Git { args : _ } | Switch { name : _ } | GitIgnore => unreachable!(),
}

View File

@ -296,4 +296,17 @@ pub fn list(vault_folder : &path::Path) -> Result<(), error::Error> {
Ok(())
}
pub fn clean(vault_folder : &path::Path) -> Result<(), error::Error> {
let tasks = Task::load_all(vault_folder, false)?;
for task in tasks {
if task.data.discarded {
task.delete()?;
}
}
Ok(())
}