@@ -31,15 +31,15 @@ import (
31
31
32
32
// Project represents all the profiles defined for the sketch
33
33
type Project struct {
34
- Profiles map [ string ] * Profile `yaml:"profiles"`
35
- DefaultProfile string `yaml:"default_profile"`
34
+ Profiles Profiles `yaml:"profiles"`
35
+ DefaultProfile string `yaml:"default_profile"`
36
36
}
37
37
38
38
// AsYaml outputs the project file as Yaml
39
39
func (p * Project ) AsYaml () string {
40
40
res := "profiles:\n "
41
- for name , profile := range p .Profiles {
42
- res += fmt .Sprintf (" %s:\n " , name )
41
+ for _ , profile := range p .Profiles {
42
+ res += fmt .Sprintf (" %s:\n " , profile . Name )
43
43
res += profile .AsYaml ()
44
44
res += "\n "
45
45
}
@@ -49,9 +49,38 @@ func (p *Project) AsYaml() string {
49
49
return res
50
50
}
51
51
52
+ // Profiles are a list of Profile
53
+ type Profiles []* Profile
54
+
55
+ // UnmarshalYAML decodes a Profiles section from YAML source.
56
+ func (p * Profiles ) UnmarshalYAML (unmarshal func (interface {}) error ) error {
57
+ unmarshaledProfiles := map [string ]* Profile {}
58
+ if err := unmarshal (& unmarshaledProfiles ); err != nil {
59
+ return err
60
+ }
61
+
62
+ var profilesData yaml.MapSlice
63
+ if err := unmarshal (& profilesData ); err != nil {
64
+ return err
65
+ }
66
+
67
+ for _ , profileData := range profilesData {
68
+ profileName , ok := profileData .Key .(string )
69
+ if ! ok {
70
+ return fmt .Errorf ("invalid profile name: %v" , profileData .Key )
71
+ }
72
+ profile := unmarshaledProfiles [profileName ]
73
+ profile .Name = profileName
74
+ * p = append (* p , profile )
75
+ }
76
+
77
+ return nil
78
+ }
79
+
52
80
// Profile is a sketch profile, it contains a reference to all the resources
53
81
// needed to build and upload a sketch
54
82
type Profile struct {
83
+ Name string
55
84
Notes string `yaml:"notes"`
56
85
FQBN string `yaml:"fqbn"`
57
86
Platforms ProfileRequiredPlatforms `yaml:"platforms"`
0 commit comments