Skip to content

Commit

Permalink
feat: task confirmation (#4328)
Browse files Browse the repository at this point in the history
  • Loading branch information
roele authored Feb 28, 2025
1 parent 059232c commit 097660b
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 0 deletions.
14 changes: 14 additions & 0 deletions docs/tasks/task-configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,20 @@ hide = true
run = "echo my internal task"
```

### `confirm`

- **Type**: `string`

A message to show before running the task. This is useful for tasks that are destructive or take a long
time to run. The user will be prompted to confirm before the task is run.

```toml
[tasks.release]
confirm = "Are you sure you want to cut a release?"
description = 'Cut a new release'
file = 'scripts/release.sh'
```

### `raw`

- **Type**: `bool`
Expand Down
12 changes: 12 additions & 0 deletions docs/tasks/toml-tasks.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ description = 'Run CI tasks'
depends = ['build', 'lint', 'test']

[tasks.release]
confirm = 'Are you sure you want to cut a new release?'
description = 'Cut a new release'
file = 'scripts/release.sh' # execute an external script
```
Expand Down Expand Up @@ -183,6 +184,17 @@ outputs = ['target/debug/mycli']

You can use `sources` alone if with [`mise watch`](/cli/watch.html) to run the task when the sources change.

### Confirmation

A message to show before running the task. The user will be prompted to confirm before the task is run.

```toml
[tasks.release]
confirm = 'Are you sure you want to cut a new release?'
description = 'Cut a new release'
file = 'scripts/release.sh'
```

## Specifying a shell or an interpreter {#shell-shebang}

Tasks are executed with `set -e` (`set -o erropt`) if the shell is `sh`, `bash`, or `zsh`. This means that the script
Expand Down
4 changes: 4 additions & 0 deletions schema/mise-task.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@
}
]
},
"confirm": {
"description": "confirmation message before running this task",
"type": "string"
},
"depends": {
"oneOf": [
{
Expand Down
4 changes: 4 additions & 0 deletions schema/mise.json
Original file line number Diff line number Diff line change
Expand Up @@ -1013,6 +1013,10 @@
}
]
},
"confirm": {
"description": "confirmation message before running this task",
"type": "string"
},
"depends": {
"oneOf": [
{
Expand Down
5 changes: 5 additions & 0 deletions src/cli/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,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();
Expand Down
4 changes: 4 additions & 0 deletions src/task/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ pub struct Task {
pub cf: Option<Arc<dyn ConfigFile>>,
#[serde(skip)]
pub config_root: Option<PathBuf>,
#[serde(default)]
pub confirm: Option<String>,
#[serde(default, deserialize_with = "deserialize_arr")]
pub depends: Vec<TaskDep>,
#[serde(default, deserialize_with = "deserialize_arr")]
Expand Down Expand Up @@ -177,6 +179,7 @@ impl Task {
.or(p.parse_str("alias").map(|s| vec![s]))
.or(p.parse_str("aliases").map(|s| vec![s]))
.unwrap_or_default();
task.confirm = p.parse_str("confirm");
task.description = p.parse_str("description").unwrap_or_default();
task.sources = p.parse_array("sources").unwrap_or_default();
task.outputs = info.get("outputs").map(|to| to.into()).unwrap_or_default();
Expand Down Expand Up @@ -577,6 +580,7 @@ impl Default for Task {
config_source: PathBuf::new(),
cf: None,
config_root: None,
confirm: None,
depends: vec![],
depends_post: vec![],
wait_for: vec![],
Expand Down

0 comments on commit 097660b

Please sign in to comment.