clean command
This commit is contained in:
parent
f43d583ae6
commit
6aa3eb4e83
@ -44,4 +44,3 @@ Run `--help` alongside any command to get details on what it does.
|
|||||||
- Due dates
|
- Due dates
|
||||||
- Taken as input when creating notes
|
- Taken as input when creating notes
|
||||||
- Displayed in list view by default (with number of days remaining)
|
- Displayed in list view by default (with number of days remaining)
|
||||||
- `clean` command to delete discarded tasks
|
|
||||||
|
@ -48,6 +48,8 @@ enum Command {
|
|||||||
Delete {
|
Delete {
|
||||||
id_or_name : String,
|
id_or_name : String,
|
||||||
},
|
},
|
||||||
|
/// Deletes all discarded tasks.
|
||||||
|
Clean,
|
||||||
/// Discard a task without deleting the underlying file.
|
/// Discard a task without deleting the underlying file.
|
||||||
Discard {
|
Discard {
|
||||||
id_or_name : String,
|
id_or_name : String,
|
||||||
@ -242,6 +244,10 @@ fn program() -> Result<(), error::Error> {
|
|||||||
List {} => {
|
List {} => {
|
||||||
tasks::list(vault_folder)?;
|
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.
|
// All commands which are dealt with in if let chain at start.
|
||||||
Vault(_) | Config(_) | Git { args : _ } | Switch { name : _ } | GitIgnore => unreachable!(),
|
Vault(_) | Config(_) | Git { args : _ } | Switch { name : _ } | GitIgnore => unreachable!(),
|
||||||
}
|
}
|
||||||
|
13
src/tasks.rs
13
src/tasks.rs
@ -296,4 +296,17 @@ pub fn list(vault_folder : &path::Path) -> Result<(), error::Error> {
|
|||||||
Ok(())
|
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(())
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user