@@ -29,10 +29,18 @@ import (
29
29
"gopkg.in/yaml.v3"
30
30
)
31
31
32
+ // projectRaw is a support struct used only to unmarshal the yaml
33
+ type projectRaw struct {
34
+ ProfilesRaw yaml.Node `yaml:"profiles"`
35
+ DefaultProfile string `yaml:"default_profile"`
36
+ DefaultFqbn string `yaml:"default_fqbn"`
37
+ DefaultPort string `yaml:"default_port,omitempty"`
38
+ DefaultProtocol string `yaml:"default_protocol,omitempty"`
39
+ }
40
+
32
41
// Project represents the sketch project file
33
42
type Project struct {
34
- ProfilesRaw yaml.Node `yaml:"profiles"`
35
- Profiles []* Profile `yaml:"-"`
43
+ Profiles []* Profile `yaml:"profiles"`
36
44
DefaultProfile string `yaml:"default_profile"`
37
45
DefaultFqbn string `yaml:"default_fqbn"`
38
46
DefaultPort string `yaml:"default_port,omitempty"`
@@ -63,7 +71,7 @@ func (p *Project) AsYaml() string {
63
71
return res
64
72
}
65
73
66
- func (p * Project ) getProfiles () []* Profile {
74
+ func (p * projectRaw ) getProfiles () []* Profile {
67
75
profiles := []* Profile {}
68
76
for i , node := range p .ProfilesRaw .Content {
69
77
if node .Tag != "!!str" {
@@ -80,25 +88,7 @@ func (p *Project) getProfiles() []*Profile {
80
88
return profiles
81
89
}
82
90
83
- // Profiles are a list of Profile
84
- type Profiles []* Profile
85
-
86
91
// UnmarshalYAML decodes a Profiles section from YAML source.
87
- func (p * Profiles ) UnmarshalYAML (unmarshal func (interface {}) error ) error {
88
- unmarshaledProfiles := map [string ]* Profile {}
89
- if err := unmarshal (& unmarshaledProfiles ); err != nil {
90
- return err
91
- }
92
-
93
- for k , v := range unmarshaledProfiles {
94
- profile := v
95
- profile .Name = k
96
- * p = append (* p , profile )
97
- }
98
-
99
- return nil
100
- }
101
-
102
92
// Profile is a sketch profile, it contains a reference to all the resources
103
93
// needed to build and upload a sketch
104
94
type Profile struct {
@@ -266,11 +256,16 @@ func LoadProjectFile(file *paths.Path) (*Project, error) {
266
256
if err != nil {
267
257
return nil , err
268
258
}
269
- res := & Project {}
270
- if err := yaml .Unmarshal (data , & res ); err != nil {
259
+ raw := & projectRaw {}
260
+ if err := yaml .Unmarshal (data , & raw ); err != nil {
271
261
return nil , err
272
262
}
273
- res .Profiles = res .getProfiles ()
274
263
275
- return res , nil
264
+ return & Project {
265
+ Profiles : raw .getProfiles (),
266
+ DefaultProfile : raw .DefaultProfile ,
267
+ DefaultFqbn : raw .DefaultFqbn ,
268
+ DefaultPort : raw .DefaultPort ,
269
+ DefaultProtocol : raw .DefaultProtocol ,
270
+ }, nil
276
271
}
0 commit comments