-
-
Notifications
You must be signed in to change notification settings - Fork 811
Expand file tree
/
Copy pathcmd.go
More file actions
121 lines (108 loc) · 2.57 KB
/
cmd.go
File metadata and controls
121 lines (108 loc) · 2.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
package ast
import (
"go.yaml.in/yaml/v3"
"github.com/go-task/task/v3/errors"
"github.com/go-task/task/v3/internal/deepcopy"
)
// Cmd is a task command
type Cmd struct {
Cmd string
Task string
For *For
If string
Silent bool
Set []string
Shopt []string
Vars *Vars
IgnoreError bool
Defer bool
Platforms []*Platform
}
func (c *Cmd) DeepCopy() *Cmd {
if c == nil {
return nil
}
return &Cmd{
Cmd: c.Cmd,
Task: c.Task,
For: c.For.DeepCopy(),
If: c.If,
Silent: c.Silent,
Set: deepcopy.Slice(c.Set),
Shopt: deepcopy.Slice(c.Shopt),
Vars: c.Vars.DeepCopy(),
IgnoreError: c.IgnoreError,
Defer: c.Defer,
Platforms: deepcopy.Slice(c.Platforms),
}
}
func (c *Cmd) UnmarshalYAML(node *yaml.Node) error {
switch node.Kind {
case yaml.ScalarNode:
var cmd string
if err := node.Decode(&cmd); err != nil {
return errors.NewTaskfileDecodeError(err, node)
}
c.Cmd = cmd
return nil
case yaml.MappingNode:
var cmdStruct struct {
Cmd string
Task string
For *For
If string
Silent bool
Set []string
Shopt []string
Vars *Vars
IgnoreError bool `yaml:"ignore_error"`
Defer *Defer
Platforms []*Platform
}
if err := node.Decode(&cmdStruct); err != nil {
return errors.NewTaskfileDecodeError(err, node)
}
if cmdStruct.Defer != nil {
// A deferred command
if cmdStruct.Defer.Cmd != "" {
c.Defer = true
c.Cmd = cmdStruct.Defer.Cmd
c.Silent = cmdStruct.Silent
return nil
}
// A deferred task call
if cmdStruct.Defer.Task != "" {
c.Defer = true
c.Task = cmdStruct.Defer.Task
c.Vars = cmdStruct.Defer.Vars
c.Silent = cmdStruct.Defer.Silent
return nil
}
return nil
}
// A task call
if cmdStruct.Task != "" {
c.Task = cmdStruct.Task
c.Vars = cmdStruct.Vars
c.For = cmdStruct.For
c.If = cmdStruct.If
c.Silent = cmdStruct.Silent
c.IgnoreError = cmdStruct.IgnoreError
return nil
}
// A command with additional options
if cmdStruct.Cmd != "" {
c.Cmd = cmdStruct.Cmd
c.For = cmdStruct.For
c.If = cmdStruct.If
c.Silent = cmdStruct.Silent
c.Set = cmdStruct.Set
c.Shopt = cmdStruct.Shopt
c.IgnoreError = cmdStruct.IgnoreError
c.Platforms = cmdStruct.Platforms
return nil
}
return errors.NewTaskfileDecodeError(nil, node).WithMessage("invalid keys in command")
}
return errors.NewTaskfileDecodeError(nil, node).WithTypeMessage("command")
}