Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add methods to set and retrieve default_programmer from a sketch
  • Loading branch information
MatteoPologruto committed Jan 18, 2024
commit d94ea8c34260970bf504570860288e8f6c61c8d1
31 changes: 22 additions & 9 deletions internal/arduino/sketch/sketch.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,12 @@ func (s *Sketch) GetDefaultPortAddressAndProtocol() (string, string) {
return s.Project.DefaultPort, s.Project.DefaultProtocol
}

// GetDefaultProgrammer return the default Programmer for the sketch (from the sketch.yaml project file),
// ore the empty string if not set.
func (s *Sketch) GetDefaultProgrammer() string {
return s.Project.DefaultProgrammer
}

// SetDefaultFQBN sets the default FQBN for the sketch and saves it in the sketch.yaml project file.
func (s *Sketch) SetDefaultFQBN(fqbn string) error {
s.Project.DefaultFqbn = fqbn
Expand All @@ -263,6 +269,12 @@ func (s *Sketch) SetDefaultPort(address, protocol string) error {
return updateOrAddYamlRootEntry(s.GetProjectPath(), "default_protocol", protocol)
}

// SetDefaultFQBN sets the default programmer for the sketch and saves it in the sketch.yaml project file.
func (s *Sketch) SetDefaultProgrammer(programmer string) error {
s.Project.DefaultProgrammer = programmer
return updateOrAddYamlRootEntry(s.GetProjectPath(), "default_programmer", programmer)
}

// InvalidSketchFolderNameError is returned when the sketch directory doesn't match the sketch name
type InvalidSketchFolderNameError struct {
SketchFolder *paths.Path
Expand Down Expand Up @@ -290,15 +302,16 @@ func (s *Sketch) Hash() string {
func (s *Sketch) ToRpc() *rpc.Sketch {
defaultPort, defaultProtocol := s.GetDefaultPortAddressAndProtocol()
res := &rpc.Sketch{
MainFile: s.MainFile.String(),
LocationPath: s.FullPath.String(),
OtherSketchFiles: s.OtherSketchFiles.AsStrings(),
AdditionalFiles: s.AdditionalFiles.AsStrings(),
RootFolderFiles: s.RootFolderFiles.AsStrings(),
DefaultFqbn: s.GetDefaultFQBN(),
DefaultPort: defaultPort,
DefaultProtocol: defaultProtocol,
Profiles: f.Map(s.Project.Profiles, (*Profile).ToRpc),
MainFile: s.MainFile.String(),
LocationPath: s.FullPath.String(),
OtherSketchFiles: s.OtherSketchFiles.AsStrings(),
AdditionalFiles: s.AdditionalFiles.AsStrings(),
RootFolderFiles: s.RootFolderFiles.AsStrings(),
DefaultFqbn: s.GetDefaultFQBN(),
DefaultPort: defaultPort,
DefaultProtocol: defaultProtocol,
DefaultProgrammer: s.GetDefaultProgrammer(),
Profiles: f.Map(s.Project.Profiles, (*Profile).ToRpc),
}
if defaultProfile, err := s.GetProfile(s.Project.DefaultProfile); err == nil {
res.DefaultProfile = defaultProfile.ToRpc()
Expand Down