mirror of
https://github.com/go-task/task.git
synced 2025-08-08 22:36:57 +02:00
wip
This commit is contained in:
@@ -2,6 +2,8 @@ package ast
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/go-task/task/v3/internal/deepcopy"
|
||||||
|
"sync"
|
||||||
|
|
||||||
"gopkg.in/yaml.v3"
|
"gopkg.in/yaml.v3"
|
||||||
|
|
||||||
@@ -9,9 +11,27 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// Precondition represents a precondition necessary for a task to run
|
// Precondition represents a precondition necessary for a task to run
|
||||||
type Precondition struct {
|
type (
|
||||||
|
Preconditions struct {
|
||||||
|
preconditions []*Precondition
|
||||||
|
mutex sync.RWMutex
|
||||||
|
}
|
||||||
|
|
||||||
|
Precondition struct {
|
||||||
Sh string
|
Sh string
|
||||||
Msg string
|
Msg string
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
func (p *Preconditions) DeepCopy() *Preconditions {
|
||||||
|
if p == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
defer p.mutex.RUnlock()
|
||||||
|
p.mutex.RLock()
|
||||||
|
return &Preconditions{
|
||||||
|
preconditions: deepcopy.Slice(p.preconditions),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Precondition) DeepCopy() *Precondition {
|
func (p *Precondition) DeepCopy() *Precondition {
|
||||||
@@ -24,6 +44,12 @@ func (p *Precondition) DeepCopy() *Precondition {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func NewPreconditions() *Preconditions {
|
||||||
|
return &Preconditions{
|
||||||
|
preconditions: make([]*Precondition, 0),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// UnmarshalYAML implements yaml.Unmarshaler interface.
|
// UnmarshalYAML implements yaml.Unmarshaler interface.
|
||||||
func (p *Precondition) UnmarshalYAML(node *yaml.Node) error {
|
func (p *Precondition) UnmarshalYAML(node *yaml.Node) error {
|
||||||
switch node.Kind {
|
switch node.Kind {
|
||||||
@@ -55,3 +81,16 @@ func (p *Precondition) UnmarshalYAML(node *yaml.Node) error {
|
|||||||
|
|
||||||
return errors.NewTaskfileDecodeError(nil, node).WithTypeMessage("precondition")
|
return errors.NewTaskfileDecodeError(nil, node).WithTypeMessage("precondition")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (p *Preconditions) UnmarshalYAML(node *yaml.Node) error {
|
||||||
|
|
||||||
|
if p == nil || p.preconditions == nil {
|
||||||
|
*p = *NewPreconditions()
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := node.Decode(&p.preconditions); err != nil {
|
||||||
|
return errors.NewTaskfileDecodeError(err, node).WithTypeMessage("precondition")
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
@@ -29,6 +29,7 @@ type Taskfile struct {
|
|||||||
Shopt []string
|
Shopt []string
|
||||||
Vars *Vars
|
Vars *Vars
|
||||||
Env *Vars
|
Env *Vars
|
||||||
|
Preconditions *Preconditions
|
||||||
Tasks *Tasks
|
Tasks *Tasks
|
||||||
Silent bool
|
Silent bool
|
||||||
Dotenv []string
|
Dotenv []string
|
||||||
@@ -72,6 +73,7 @@ func (tf *Taskfile) UnmarshalYAML(node *yaml.Node) error {
|
|||||||
Output Output
|
Output Output
|
||||||
Method string
|
Method string
|
||||||
Includes *Includes
|
Includes *Includes
|
||||||
|
Preconditions *Preconditions
|
||||||
Set []string
|
Set []string
|
||||||
Shopt []string
|
Shopt []string
|
||||||
Vars *Vars
|
Vars *Vars
|
||||||
@@ -110,6 +112,10 @@ func (tf *Taskfile) UnmarshalYAML(node *yaml.Node) error {
|
|||||||
if tf.Tasks == nil {
|
if tf.Tasks == nil {
|
||||||
tf.Tasks = NewTasks()
|
tf.Tasks = NewTasks()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if tf.Preconditions == nil {
|
||||||
|
tf.Preconditions = NewPreconditions()
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user