Skip to content

Commit 1f0681e

Browse files
committed
Added Profile.ToRpc helper
1 parent 3495fff commit 1f0681e

File tree

2 files changed

+16
-11
lines changed

2 files changed

+16
-11
lines changed

commands/sketch/load.go

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@ import (
2626

2727
// LoadSketch collects and returns all files composing a sketch
2828
func LoadSketch(ctx context.Context, req *rpc.LoadSketchRequest) (*rpc.LoadSketchResponse, error) {
29-
// TODO: This should be a ToRpc function for the Sketch struct
3029
sk, err := sketch.New(paths.New(req.GetSketchPath()))
3130
if err != nil {
3231
return nil, &cmderrors.CantOpenSketchError{Cause: err}
3332
}
3433

34+
// TODO: This should be a ToRpc function for the Sketch struct
3535
otherSketchFiles := make([]string, sk.OtherSketchFiles.Len())
3636
for i, file := range sk.OtherSketchFiles {
3737
otherSketchFiles[i] = file.String()
@@ -57,14 +57,7 @@ func LoadSketch(ctx context.Context, req *rpc.LoadSketchRequest) (*rpc.LoadSketc
5757
}
5858
}
5959

60-
defaultProfileResp := &rpc.SketchProfile{}
61-
defaultProfile, err := sk.GetProfile(sk.Project.DefaultProfile)
62-
if err == nil {
63-
defaultProfileResp.Name = defaultProfile.Name
64-
defaultProfileResp.Fqbn = defaultProfile.FQBN
65-
}
66-
67-
return &rpc.LoadSketchResponse{
60+
res := &rpc.LoadSketchResponse{
6861
MainFile: sk.MainFile.String(),
6962
LocationPath: sk.FullPath.String(),
7063
OtherSketchFiles: otherSketchFiles,
@@ -74,6 +67,9 @@ func LoadSketch(ctx context.Context, req *rpc.LoadSketchRequest) (*rpc.LoadSketc
7467
DefaultPort: defaultPort,
7568
DefaultProtocol: defaultProtocol,
7669
Profiles: profiles,
77-
DefaultProfile: defaultProfileResp,
78-
}, nil
70+
}
71+
if defaultProfile, err := sk.GetProfile(sk.Project.DefaultProfile); err == nil {
72+
res.DefaultProfile = defaultProfile.ToRpc()
73+
}
74+
return res, nil
7975
}

internal/arduino/sketch/profiles.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
"strings"
2525

2626
"github.com/arduino/arduino-cli/internal/arduino/utils"
27+
rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1"
2728
"github.com/arduino/go-paths-helper"
2829
semver "go.bug.st/relaxed-semver"
2930
"gopkg.in/yaml.v3"
@@ -99,6 +100,14 @@ type Profile struct {
99100
Libraries ProfileRequiredLibraries `yaml:"libraries"`
100101
}
101102

103+
// ToRpc converts this Profile to an rpc.SketchProfile
104+
func (p *Profile) ToRpc() *rpc.SketchProfile {
105+
return &rpc.SketchProfile{
106+
Name: p.Name,
107+
Fqbn: p.FQBN,
108+
}
109+
}
110+
102111
// AsYaml outputs the profile as Yaml
103112
func (p *Profile) AsYaml() string {
104113
res := ""

0 commit comments

Comments
 (0)