Skip to content

Commit da64af5

Browse files
committed
Added methods to get profiles from sketch
1 parent 1b1867f commit da64af5

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

arduino/sketch/sketch.go

+16
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ type Sketch struct {
3939
AdditionalFiles paths.PathList
4040
RootFolderFiles paths.PathList // All files that are in the Sketch root
4141
Metadata *Metadata
42+
Project *Project
4243
}
4344

4445
// Metadata is the kind of data associated to a project such as the connected board
@@ -93,6 +94,15 @@ func New(path *paths.Path) (*Sketch, error) {
9394
Metadata: new(Metadata),
9495
}
9596

97+
projectFile := path.Join("sketch.yml")
98+
if projectFile.Exist() {
99+
prj, err := LoadProjectFile(projectFile)
100+
if err != nil {
101+
return nil, fmt.Errorf("%s %w", tr("error loading project file:"), err)
102+
}
103+
sketch.Project = prj
104+
}
105+
96106
err := sketch.checkSketchCasing()
97107
if e, ok := err.(*InvalidSketchFolderNameError); ok {
98108
return nil, e
@@ -218,6 +228,12 @@ func (s *Sketch) ExportMetadata() error {
218228
return nil
219229
}
220230

231+
// GetProfile returns the requested profile or nil if the profile
232+
// is not found.
233+
func (s *Sketch) GetProfile(profileName string) *Profile {
234+
return s.Project.Profiles[profileName]
235+
}
236+
221237
// checkSketchCasing returns an error if the casing of the sketch folder and the main file are different.
222238
// Correct:
223239
// MySketch/MySketch.ino

0 commit comments

Comments
 (0)