From 6aa3eb4e833a1cbb14b8fc5e1e2a56e008ae9761 Mon Sep 17 00:00:00 2001 From: aaron-jack-manning Date: Mon, 22 Aug 2022 18:58:13 +1000 Subject: [PATCH] clean command --- README.md | 1 - src/main.rs | 6 ++++++ src/tasks.rs | 13 +++++++++++++ 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 73269d2..a1b49e9 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/src/main.rs b/src/main.rs index 0f01b06..b7bf7db 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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!(), } diff --git a/src/tasks.rs b/src/tasks.rs index 8c89187..dab7d4d 100644 --- a/src/tasks.rs +++ b/src/tasks.rs @@ -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(()) +} +