mirror of
https://github.com/go-task/task.git
synced 2025-08-10 22:42:19 +02:00
feat: support negative globs (#1324)
Co-authored-by: Andrey Nering <andrey@nering.com.br>
This commit is contained in:
32
taskfile/glob.go
Normal file
32
taskfile/glob.go
Normal file
@@ -0,0 +1,32 @@
|
||||
package taskfile
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"gopkg.in/yaml.v3"
|
||||
)
|
||||
|
||||
type Glob struct {
|
||||
Glob string
|
||||
Negate bool
|
||||
}
|
||||
|
||||
func (g *Glob) UnmarshalYAML(node *yaml.Node) error {
|
||||
switch node.Kind {
|
||||
case yaml.ScalarNode:
|
||||
g.Glob = node.Value
|
||||
return nil
|
||||
case yaml.MappingNode:
|
||||
var glob struct {
|
||||
Exclude string
|
||||
}
|
||||
if err := node.Decode(&glob); err != nil {
|
||||
return err
|
||||
}
|
||||
g.Glob = glob.Exclude
|
||||
g.Negate = true
|
||||
return nil
|
||||
default:
|
||||
return fmt.Errorf("yaml: line %d: cannot unmarshal %s into task", node.Line, node.ShortTag())
|
||||
}
|
||||
}
|
@@ -19,8 +19,8 @@ type Task struct {
|
||||
Summary string
|
||||
Requires *Requires
|
||||
Aliases []string
|
||||
Sources []string
|
||||
Generates []string
|
||||
Sources []*Glob
|
||||
Generates []*Glob
|
||||
Status []string
|
||||
Preconditions []*Precondition
|
||||
Dir string
|
||||
@@ -83,8 +83,8 @@ func (t *Task) UnmarshalYAML(node *yaml.Node) error {
|
||||
Prompt string
|
||||
Summary string
|
||||
Aliases []string
|
||||
Sources []string
|
||||
Generates []string
|
||||
Sources []*Glob
|
||||
Generates []*Glob
|
||||
Status []string
|
||||
Preconditions []*Precondition
|
||||
Dir string
|
||||
|
Reference in New Issue
Block a user