Skip to content

Commit

Permalink
add --delete option for mark command
Browse files Browse the repository at this point in the history
will mark the selected tasks as "done" meanwhile delete them if --delete
used
  • Loading branch information
jfding committed Oct 10, 2024
1 parent 5c97356 commit 4c6aee6
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
5 changes: 4 additions & 1 deletion src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,10 @@ pub enum Commands {

/// -> mark item as done
#[clap(visible_alias("m"))]
Mark,
Mark {
#[arg(short, long)]
delete: bool,
},

/// -> list all uncompeleted tasks in box
#[clap(visible_aliases(["l", "ls"]))]
Expand Down
4 changes: 2 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,15 +132,15 @@ fn main() {
TaskBox::new(util::get_inbox_file("today")).collect_from(&mut tb_from)
}

Some(Commands::Mark) => {
Some(Commands::Mark { delete } ) => {
let mut todo = TaskBox::new(inbox_path);
let tasks = todo.get_all_to_mark();
if tasks.is_empty() {
println!(" {} left!", S_empty!("nothing"));
return
}

todo.mark(i_select(tasks, "choose to close:"));
todo.mark(i_select(tasks, "choose to close:"), delete);
}

Some(Commands::Add { what, date_stamp, routine, non_interactive }) => {
Expand Down
6 changes: 5 additions & 1 deletion src/taskbox.rs
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ impl TaskBox {
self.tasks.iter().filter(|(_, done)| !done).count()
}

pub fn mark(&mut self, items: Vec<String>) {
pub fn mark(&mut self, items: Vec<String>, delete: bool) {
self.load();

if items.is_empty() || self.tasks.is_empty() {
Expand All @@ -443,6 +443,10 @@ impl TaskBox {
}
}

if delete {
self.tasks.retain(|(task, done)| !done || !items.contains(task))
}

self._dump();
}

Expand Down

0 comments on commit 4c6aee6

Please sign in to comment.