From fa3ac8519cb24221790ef93216126818b580d4bf Mon Sep 17 00:00:00 2001 From: Roland Schaer Date: Mon, 3 Feb 2025 18:49:09 -0300 Subject: [PATCH] feat: task confirmation --- schema/mise-task.json | 4 ++++ schema/mise.json | 4 ++++ src/cli/run.rs | 5 +++++ src/task/mod.rs | 3 +++ 4 files changed, 16 insertions(+) diff --git a/schema/mise-task.json b/schema/mise-task.json index 650dcc5172..057d35ea90 100644 --- a/schema/mise-task.json +++ b/schema/mise-task.json @@ -37,6 +37,10 @@ } ] }, + "confirm": { + "description": "confirmation message before running this task", + "type": "string" + }, "depends": { "oneOf": [ { diff --git a/schema/mise.json b/schema/mise.json index 7e3867abe0..d0917a5ca0 100644 --- a/schema/mise.json +++ b/schema/mise.json @@ -1012,6 +1012,10 @@ } ] }, + "confirm": { + "description": "confirmation message before running this task", + "type": "string" + }, "depends": { "oneOf": [ { diff --git a/src/cli/run.rs b/src/cli/run.rs index bda87e1133..4de5b0ba2c 100644 --- a/src/cli/run.rs +++ b/src/cli/run.rs @@ -429,6 +429,11 @@ impl Run { } return Ok(()); } + if let Some(message) = &task.confirm { + if !ui::confirm(message).unwrap_or(true) { + return Err(eyre!("task cancelled")); + } + } let config = Config::get(); let mut tools = self.tool.clone(); diff --git a/src/task/mod.rs b/src/task/mod.rs index 57a6fcda4a..ec0885e258 100644 --- a/src/task/mod.rs +++ b/src/task/mod.rs @@ -55,6 +55,8 @@ pub struct Task { pub cf: Option>, #[serde(skip)] pub config_root: Option, + #[serde(default)] + pub confirm: Option, #[serde(default, deserialize_with = "deserialize_arr")] pub depends: Vec, #[serde(default, deserialize_with = "deserialize_arr")] @@ -572,6 +574,7 @@ impl Default for Task { config_source: PathBuf::new(), cf: None, config_root: None, + confirm: None, depends: vec![], depends_post: vec![], wait_for: vec![],