| 11 | #[async_trait] |
| 12 | impl Command for DeleteCommand { |
| 13 | async fn execute(&self, ctx: &AppContext) -> Result<(), Box<dyn Error>> { |
| 14 | if self.task_ids.is_empty() { |
| 15 | return Err("No task IDs provided".into()); |
| 16 | } |
| 17 | |
| 18 | let task_manager = TaskManager::new(ctx)?; |
| 19 | let mut successful_deletes = 0; |
| 20 | let mut failed_deletes = 0; |
| 21 | |
| 22 | for task_id in &self.task_ids { |
| 23 | match task_manager.delete_task(task_id).await { |
| 24 | Ok(()) => { |
| 25 | println!("Deleted {task_id}"); |
| 26 | successful_deletes += 1; |
| 27 | } |
| 28 | Err(e) => { |
| 29 | eprintln!("Failed to delete {task_id}: {e}"); |
| 30 | failed_deletes += 1; |
| 31 | } |
| 32 | } |
| 33 | } |
| 34 | |
| 35 | if failed_deletes > 0 { |
| 36 | if successful_deletes > 0 { |
| 37 | println!("\n{successful_deletes} deleted, {failed_deletes} failed"); |
| 38 | } |
| 39 | return Err(format!("{failed_deletes} task(s) failed to delete").into()); |
| 40 | } |
| 41 | |
| 42 | Ok(()) |
| 43 | } |
| 44 | } |
| 45 | |
| 46 | #[cfg(test)] |