mirror of
https://github.com/go-task/task.git
synced 2026-06-16 04:11:40 +00:00
feat(cmd): add ask option to commands
Add an `ask` attribute to commands that shows a y/n confirmation
before executing. If the user declines, the command is skipped but
the task continues with the next command.
Example:
```yaml
cmds:
- cmd: echo "Deploying..."
ask: "Deploy to production?"
- task: run-migrations
ask: "Run database migrations?"
```
Behavior:
- Default: asks for y/n confirmation
- --yes: auto-confirms all asks
- --dry: shows commands without asking
This differs from task-level `prompt:` which cancels the entire task
if declined. Command-level `ask:` only skips the individual command.
This commit is contained in:
@@ -20,6 +20,7 @@ type Cmd struct {
|
||||
IgnoreError bool
|
||||
Defer bool
|
||||
Platforms []*Platform
|
||||
Ask string
|
||||
}
|
||||
|
||||
func (c *Cmd) DeepCopy() *Cmd {
|
||||
@@ -38,6 +39,7 @@ func (c *Cmd) DeepCopy() *Cmd {
|
||||
IgnoreError: c.IgnoreError,
|
||||
Defer: c.Defer,
|
||||
Platforms: deepcopy.Slice(c.Platforms),
|
||||
Ask: c.Ask,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -65,6 +67,7 @@ func (c *Cmd) UnmarshalYAML(node *yaml.Node) error {
|
||||
IgnoreError bool `yaml:"ignore_error"`
|
||||
Defer *Defer
|
||||
Platforms []*Platform
|
||||
Ask string
|
||||
}
|
||||
if err := node.Decode(&cmdStruct); err != nil {
|
||||
return errors.NewTaskfileDecodeError(err, node)
|
||||
@@ -98,6 +101,7 @@ func (c *Cmd) UnmarshalYAML(node *yaml.Node) error {
|
||||
c.If = cmdStruct.If
|
||||
c.Silent = cmdStruct.Silent
|
||||
c.IgnoreError = cmdStruct.IgnoreError
|
||||
c.Ask = cmdStruct.Ask
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -111,6 +115,7 @@ func (c *Cmd) UnmarshalYAML(node *yaml.Node) error {
|
||||
c.Shopt = cmdStruct.Shopt
|
||||
c.IgnoreError = cmdStruct.IgnoreError
|
||||
c.Platforms = cmdStruct.Platforms
|
||||
c.Ask = cmdStruct.Ask
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user