forked from devfile/library
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwriter.go
32 lines (27 loc) · 748 Bytes
/
writer.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
package parser
import (
"sigs.k8s.io/yaml"
"github.com/devfile/library/pkg/testingutil/filesystem"
"github.com/pkg/errors"
"k8s.io/klog"
)
// WriteYamlDevfile creates a devfile.yaml file
func (d *DevfileObj) WriteYamlDevfile() error {
// Encode data into YAML format
yamlData, err := yaml.Marshal(d.Data)
if err != nil {
return errors.Wrapf(err, "failed to marshal devfile object into yaml")
}
// Write to devfile.yaml
fs := d.Ctx.GetFs()
if fs == nil {
fs = filesystem.DefaultFs{}
}
err = fs.WriteFile(d.Ctx.GetAbsPath(), yamlData, 0644)
if err != nil {
return errors.Wrapf(err, "failed to create devfile yaml file")
}
// Successful
klog.V(2).Infof("devfile yaml created at: '%s'", OutputDevfileYamlPath)
return nil
}