Skip to content

Commit

Permalink
Merge pull request #16 from jfding/purge-and-sort
Browse files Browse the repository at this point in the history
add --sort arg to cmd purgo to make it sort and save
  • Loading branch information
jfding authored Sep 16, 2024
2 parents 5ca4ffd + fd5695d commit 4fff3d3
Show file tree
Hide file tree
Showing 3 changed files with 10 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 @@ -53,7 +53,10 @@ pub enum Commands {
Glance,

/// -> purge all the duplicated lines
Purge, // no alias for safe
Purge {
#[arg(short, long)]
sort: bool,
}, // no alias for safe

/// -> sink all outdated uncompeleted to "today"
Sink {
Expand Down
4 changes: 2 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,13 +119,13 @@ fn main() {
TaskBox::list_boxes(inbox_path)
}

Some(Commands::Purge) => {
Some(Commands::Purge { sort }) => {
if inquire::Confirm::new("are you sure?")
.with_default(false)
.prompt().unwrap_or(false) {

let mut todo = TaskBox::new(inbox_path);
todo.purge();
todo.purge(sort);
}
}

Expand Down
5 changes: 4 additions & 1 deletion src/taskbox.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ impl TaskBox {
self._dump();
}

pub fn purge(&mut self) {
pub fn purge(&mut self, sort: bool) {
use std::collections::HashSet;

self._load();
Expand Down Expand Up @@ -223,6 +223,9 @@ impl TaskBox {
}
}

// (optional) 3rd scan: sort by completed and uncomplated
if sort { newtasks.sort_by(|a, b| a.1.cmp(&b.1)) }

self.tasks = newtasks;
self._dump();
}
Expand Down

0 comments on commit 4fff3d3

Please sign in to comment.