Skip to content

Commit

Permalink
delete by status
Browse files Browse the repository at this point in the history
  • Loading branch information
jhspetersson committed Sep 20, 2024
1 parent 09e044d commit b2e4149
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 5 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -202,11 +202,13 @@ Show total task count, count by status and top 10 authors.

### delete

Deletes one or more tasks by their IDs.
Deletes one or more tasks by their IDs or status.

git task delete 1
git task delete 2 3 4 5 10 12
git task delete 2..5 10 12
git task delete -s CLOSED
git task delete -s c

Also delete a corresponding GitHub issue:

Expand Down
8 changes: 6 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,11 @@ enum Command {
#[clap(visible_aliases(["del", "remove", "rem"]))]
Delete {
/// space separated task IDs
ids: Vec<String>,
#[clap(required = true)]
ids: Option<Vec<String>>,
/// Delete by status (by default: o - OPEN, i - IN_PROGRESS, c - CLOSED)
#[arg(short, long, value_delimiter = ',', conflicts_with = "ids", required_unless_present = "ids")]
status: Option<Vec<String>>,
/// Also delete task from the remote source (e.g., GitHub)
#[arg(short, long)]
push: bool,
Expand Down Expand Up @@ -474,7 +478,7 @@ fn main() -> ExitCode {
Some(Command::Pull { ids, limit, status, remote, no_comments }) => task_pull(ids, limit, status, &remote, no_comments),
Some(Command::Push { ids, remote, no_comments, no_color }) => task_push(ids, &remote, no_comments, no_color),
Some(Command::Stats { no_color }) => task_stats(no_color),
Some(Command::Delete { ids, push, remote }) => task_delete(ids, push, &remote),
Some(Command::Delete { ids, status, push, remote }) => task_delete(ids, status, push, &remote),
Some(Command::Clear) => task_clear(),
Some(Command::Config { subcommand }) => task_config(subcommand),
None => false
Expand Down
26 changes: 24 additions & 2 deletions src/operations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -637,9 +637,31 @@ fn create_remote_comment(connector: &Box<&'static dyn RemoteConnector>, user: &S
}
}

pub(crate) fn task_delete(ids: Vec<String>, push: bool, remote: &Option<String>) -> bool {
let ids = ids.into_iter().expand_range().collect::<Vec<_>>();
pub(crate) fn task_delete(ids: Option<Vec<String>>, status: Option<Vec<String>>, push: bool, remote: &Option<String>) -> bool {
let ids = match status {
Some(statuses) => {
match gittask::list_tasks() {
Ok(tasks) => {
let status_manager = StatusManager::new();
let statuses = statuses.iter().map(|s| status_manager.get_full_status_name(s)).collect::<Vec<_>>();
let ids = tasks.iter().filter(|task| statuses.contains(task.get_property("status").unwrap())).map(|task| task.get_id().unwrap()).collect::<Vec<_>>();
Ok(ids)
},
Err(e) => Err(e)
}
},
None => {
let ids = ids.unwrap().into_iter().expand_range().collect::<Vec<_>>();
Ok(ids)
}
};

if let Err(e) = ids {
return error_message(e);
}
let ids = ids.unwrap();
let ids = ids.iter().map(|id| id.as_str()).collect::<Vec<_>>();

match gittask::delete_tasks(&ids) {
Ok(_) => {
println!("Task(s) {} deleted", ids.join(", "));
Expand Down

0 comments on commit b2e4149

Please sign in to comment.