@@ -31,15 +31,15 @@ import (
3131
3232// Project represents all the profiles defined for the sketch
3333type 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"`
3636}
3737
3838// AsYaml outputs the project file as Yaml
3939func (p * Project ) AsYaml () string {
4040 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 )
4343 res += profile .AsYaml ()
4444 res += "\n "
4545 }
@@ -49,9 +49,38 @@ func (p *Project) AsYaml() string {
4949 return res
5050}
5151
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+
5280// Profile is a sketch profile, it contains a reference to all the resources
5381// needed to build and upload a sketch
5482type Profile struct {
83+ Name string
5584 Notes string `yaml:"notes"`
5685 FQBN string `yaml:"fqbn"`
5786 Platforms ProfileRequiredPlatforms `yaml:"platforms"`
0 commit comments