1
0
mirror of https://github.com/go-task/task.git synced 2025-11-25 22:32:55 +02:00

feat: allow providing single or multi prompts (#1866)

* Add new type to handle single or multi prompts

* update docs

* apply review
This commit is contained in:
Matheus Mina
2024-10-29 10:37:03 -03:00
committed by GitHub
parent c4f708b222
commit 5581954fb1
7 changed files with 78 additions and 12 deletions

29
taskfile/ast/prompt.go Normal file
View File

@@ -0,0 +1,29 @@
package ast
import (
"gopkg.in/yaml.v3"
"github.com/go-task/task/v3/errors"
)
type Prompt []string
func (p *Prompt) UnmarshalYAML(node *yaml.Node) error {
switch node.Kind {
case yaml.ScalarNode:
var str string
if err := node.Decode(&str); err != nil {
return errors.NewTaskfileDecodeError(err, node)
}
*p = []string{str}
return nil
case yaml.SequenceNode:
var list []string
if err := node.Decode(&list); err != nil {
return errors.NewTaskfileDecodeError(err, node)
}
*p = list
return nil
}
return errors.NewTaskfileDecodeError(nil, node).WithTypeMessage("prompt")
}