From ea6375ea3aa6bd5b92b6be838ef994bf5d1120c2 Mon Sep 17 00:00:00 2001 From: Tino Rusch Date: Thu, 16 Jan 2025 15:34:05 +0100 Subject: [PATCH 1/2] add delete task subcommand --- src/commands/tasks.rs | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/src/commands/tasks.rs b/src/commands/tasks.rs index 1e73126..620a9f5 100644 --- a/src/commands/tasks.rs +++ b/src/commands/tasks.rs @@ -8,6 +8,7 @@ use gevulot_rs::builders::{ MsgFinishTaskBuilder, MsgRescheduleTaskBuilder, }; + use crate::{connect_to_gevulot, print_object, read_file, ChainArgs, OutputFormat}; /// Tasks command. @@ -57,6 +58,9 @@ impl Command { Subcommand::Reschedule { id } => { reschedule_task(&self.chain_args, id).await } + Subcommand::Delete { id } => { + delete_task(&self.chain_args, id).await + } }?; print_object(format, &value) } @@ -129,6 +133,12 @@ enum Subcommand { /// The ID of the task to reschedule. id: String, }, + + /// Delete a task. + Delete { + /// The ID of the task to delete. + id: String, + }, } /// Lists all tasks. @@ -342,3 +352,27 @@ pub async fn reschedule_task( "secondary": resp.secondary })) } + +pub async fn delete_task( + chain_args: &ChainArgs, + task_id: &str, +) -> Result> { + let mut client = connect_to_gevulot(chain_args).await?; + let me = client + .base_client + .write() + .await + .address + .clone() + .ok_or("No address found, did you set a mnemonic?")?; + + client.tasks.delete(gevulot_rs::proto::gevulot::gevulot::MsgDeleteTask{ + creator: me.clone(), + id: task_id.to_string(), + }).await?; + + Ok(serde_json::json!({ + "status": "success", + "message": "Task deleted successfully" + })) +} From e33d0d995477bbad51f04e1fa8d7fa72f103ed9e Mon Sep 17 00:00:00 2001 From: Tino Rusch Date: Thu, 16 Jan 2025 15:36:15 +0100 Subject: [PATCH 2/2] cargo fmt on everything --- src/commands/tasks.rs | 20 +++++++++----------- src/commands/workers.rs | 5 ++++- src/main.rs | 1 - 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/commands/tasks.rs b/src/commands/tasks.rs index 620a9f5..d36e6af 100644 --- a/src/commands/tasks.rs +++ b/src/commands/tasks.rs @@ -8,7 +8,6 @@ use gevulot_rs::builders::{ MsgFinishTaskBuilder, MsgRescheduleTaskBuilder, }; - use crate::{connect_to_gevulot, print_object, read_file, ChainArgs, OutputFormat}; /// Tasks command. @@ -55,12 +54,8 @@ impl Command { ) .await } - Subcommand::Reschedule { id } => { - reschedule_task(&self.chain_args, id).await - } - Subcommand::Delete { id } => { - delete_task(&self.chain_args, id).await - } + Subcommand::Reschedule { id } => reschedule_task(&self.chain_args, id).await, + Subcommand::Delete { id } => delete_task(&self.chain_args, id).await, }?; print_object(format, &value) } @@ -366,10 +361,13 @@ pub async fn delete_task( .clone() .ok_or("No address found, did you set a mnemonic?")?; - client.tasks.delete(gevulot_rs::proto::gevulot::gevulot::MsgDeleteTask{ - creator: me.clone(), - id: task_id.to_string(), - }).await?; + client + .tasks + .delete(gevulot_rs::proto::gevulot::gevulot::MsgDeleteTask { + creator: me.clone(), + id: task_id.to_string(), + }) + .await?; Ok(serde_json::json!({ "status": "success", diff --git a/src/commands/workers.rs b/src/commands/workers.rs index a78c68e..a00d885 100644 --- a/src/commands/workers.rs +++ b/src/commands/workers.rs @@ -1,4 +1,7 @@ -use gevulot_rs::builders::{ByteSize, ByteUnit, MsgAnnounceWorkerExitBuilder, MsgCreateWorkerBuilder, MsgDeleteWorkerBuilder}; +use gevulot_rs::builders::{ + ByteSize, ByteUnit, MsgAnnounceWorkerExitBuilder, MsgCreateWorkerBuilder, + MsgDeleteWorkerBuilder, +}; use patharg::InputArg; use serde_json::Value; use std::path::Path; diff --git a/src/main.rs b/src/main.rs index c9c1ab2..489b2b4 100644 --- a/src/main.rs +++ b/src/main.rs @@ -140,7 +140,6 @@ pub enum Command { /// Build a VM image from a container, rootfs directory, or Containerfile. Build(build::BuildArgs), - } /// Main entry point for the Gevulot Control CLI application.