@@ -2,7 +2,6 @@ package template
2
2
3
3
import (
4
4
"encoding/json"
5
- "errors"
6
5
"fmt"
7
6
"path/filepath"
8
7
"strings"
@@ -13,7 +12,7 @@ import (
13
12
)
14
13
15
14
type Step struct {
16
- Id string `json:"id" yaml:"id"`
15
+ ID string `json:"id" yaml:"id"`
17
16
Description string `json:"description" yaml:"description"`
18
17
Action string `json:"action" yaml:"action"`
19
18
Target string `json:"target" yaml:"target"`
@@ -28,13 +27,13 @@ func mergeStepsFromConfigAndTemplateFilesystem(templateFs afero.Fs, config *Temp
28
27
29
28
if config .Steps != nil {
30
29
for idx , step := range config .Steps {
31
- if step .Id == "" {
32
- step .Id = fmt .Sprintf ("Step %d" , idx )
30
+ if step .ID == "" {
31
+ step .ID = fmt .Sprintf ("Step %d" , idx )
33
32
}
34
33
step = * parseStep (& step )
35
34
36
35
if err := validateStep (step ); err != nil {
37
- allErrors = append (allErrors , errors . New ( fmt .Sprintf ("step %+v is not valid: %s" , step , err ) ))
36
+ allErrors = append (allErrors , fmt .Errorf ("step %+v is not valid: %s" , step , err ))
38
37
}
39
38
40
39
validSteps = append (validSteps , step )
@@ -49,28 +48,28 @@ func mergeStepsFromConfigAndTemplateFilesystem(templateFs afero.Fs, config *Temp
49
48
stepsFs := afero .NewBasePathFs (templateFs , "steps" )
50
49
files , err := afero .ReadDir (stepsFs , "." )
51
50
if err != nil {
52
- allErrors = append (allErrors , errors . New ( fmt .Sprintf ("problem reading steps directory: %s" , err ) ))
51
+ allErrors = append (allErrors , fmt .Errorf ("problem reading steps directory: %s" , err ))
53
52
return validSteps , allErrors
54
53
}
55
54
56
55
for _ , file := range files {
57
56
path := file .Name ()
58
57
step , err := loadStep (stepsFs , path )
59
58
if err != nil {
60
- allErrors = append (allErrors , errors . New ( fmt .Sprintf ("step %s is not valid: %s" , path , err ) ))
59
+ allErrors = append (allErrors , fmt .Errorf ("step %s is not valid: %s" , path , err ))
61
60
continue
62
61
}
63
62
64
- if step .Id == "" {
63
+ if step .ID == "" {
65
64
base := filepath .Base (path )
66
65
ext := filepath .Ext (path )
67
- step .Id = strings .TrimRight (base , ext )
66
+ step .ID = strings .TrimRight (base , ext )
68
67
}
69
68
step = parseStep (step )
70
69
71
70
err = validateStep (* step )
72
71
if err != nil {
73
- allErrors = append (allErrors , errors . New ( fmt .Sprintf ("step %s is not valid: %s" , path , err ) ))
72
+ allErrors = append (allErrors , fmt .Errorf ("step %s is not valid: %s" , path , err ))
74
73
continue
75
74
}
76
75
@@ -116,7 +115,7 @@ func loadStep(stepsFs afero.Fs, stepPath string) (*Step, error) {
116
115
case ".json" :
117
116
fileType = JSON
118
117
default :
119
- return nil , errors . New ( fmt .Sprintf ("unrecognized file extension %s" , ext ) )
118
+ return nil , fmt .Errorf ("unrecognized file extension %s" , ext )
120
119
}
121
120
122
121
step , err := readStepFile (stepsFs , stepPath , fileType )
@@ -147,7 +146,7 @@ func parseStep(step *Step) *Step {
147
146
func validateStep (step Step ) error {
148
147
if step .Action == "template" {
149
148
if step .Source == "" {
150
- return errors . New ( fmt .Sprintf ("required field source not set on step ID %s" , step .Id ) )
149
+ return fmt .Errorf ("required field source not set on step ID %s" , step .ID )
151
150
}
152
151
}
153
152
0 commit comments