Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add --sort arg to cmd purgo to make it sort and save #16

Merged
merged 1 commit into from
Sep 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading