-
Notifications
You must be signed in to change notification settings - Fork 2
/
step_input.go
44 lines (37 loc) · 1.07 KB
/
step_input.go
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
package pipeline
import (
"encoding/json"
"errors"
)
// See the comment in step_scalar.go.
// InputStep models a block or input step.
//
// Standard caveats apply - see the package comment.
type InputStep struct {
Scalar string `yaml:"-"`
Contents map[string]any `yaml:",inline"`
}
// MarshalJSON marshals s.Scalar if it's not empty, otherwise s.Contents if that
// is not empty. If both s.Scalar and s.Contents are empty, it reports an error.
func (s *InputStep) MarshalJSON() ([]byte, error) {
o, err := s.MarshalYAML()
if err != nil {
return nil, err
}
return json.Marshal(o)
}
// MarshalYAML returns s.Scalar if it's not empty, otherwise s.Contents if that
// is not empty. If both s.Scalar and s.Contents are empty, it reports an error.
func (s *InputStep) MarshalYAML() (any, error) {
if s.Scalar != "" {
return s.Scalar, nil
}
if len(s.Contents) == 0 {
return nil, errors.New("empty input step")
}
return s.Contents, nil
}
func (s InputStep) interpolate(tf stringTransformer) error {
return interpolateMap(tf, s.Contents)
}
func (*InputStep) stepTag() {}