Skip to content

Commit d998d82

Browse files
Load default profile environment when Init is called
1 parent 8497f48 commit d998d82

File tree

2 files changed

+16
-9
lines changed

2 files changed

+16
-9
lines changed

commands/instances.go

+10-4
Original file line numberDiff line numberDiff line change
@@ -242,19 +242,25 @@ func Init(req *rpc.InitRequest, responseCallback func(r *rpc.InitResponse)) erro
242242

243243
// Try to extract profile if specified
244244
var profile *sketch.Profile
245-
if req.GetProfile() != "" {
245+
if req.GetProfile() != "" || req.GetDefaultProfile() {
246246
sk, err := sketch.New(paths.New(req.GetSketchPath()))
247247
if err != nil {
248248
return &arduino.InvalidArgumentError{Cause: err}
249249
}
250-
profile = sk.GetProfile(req.GetProfile())
250+
var profileName string
251+
if req.GetProfile() != "" {
252+
profileName = req.GetProfile()
253+
} else {
254+
profileName = sk.Project.DefaultProfile
255+
}
256+
profile = sk.GetProfile(profileName)
251257
if profile == nil {
252-
return &arduino.UnknownProfileError{Profile: req.GetProfile()}
258+
return &arduino.UnknownProfileError{Profile: profileName}
253259
}
254260
responseCallback(&rpc.InitResponse{
255261
Message: &rpc.InitResponse_Profile{
256262
Profile: &rpc.Profile{
257-
Name: req.GetProfile(),
263+
Name: profileName,
258264
Fqbn: profile.FQBN,
259265
// TODO: Other profile infos may be provided here...
260266
},

internal/cli/instance/instance.go

+6-5
Original file line numberDiff line numberDiff line change
@@ -33,19 +33,19 @@ var tr = i18n.Tr
3333
// to execute further operations a valid Instance is mandatory.
3434
// If Init returns errors they're printed only.
3535
func CreateAndInit() *rpc.Instance {
36-
inst, _ := CreateAndInitWithProfile("", nil)
36+
inst, _ := CreateAndInitWithProfile("", nil, false)
3737
return inst
3838
}
3939

4040
// CreateAndInitWithProfile returns a new initialized instance using the given profile of the given sketch.
4141
// If Create fails the CLI prints an error and exits since to execute further operations a valid Instance is mandatory.
4242
// If Init returns errors they're printed only.
43-
func CreateAndInitWithProfile(profileName string, sketchPath *paths.Path) (*rpc.Instance, *rpc.Profile) {
43+
func CreateAndInitWithProfile(profileName string, sketchPath *paths.Path, defaultProfile bool) (*rpc.Instance, *rpc.Profile) {
4444
instance, err := Create()
4545
if err != nil {
4646
feedback.Fatal(tr("Error creating instance: %v", err), feedback.ErrGeneric)
4747
}
48-
profile := InitWithProfile(instance, profileName, sketchPath)
48+
profile := InitWithProfile(instance, profileName, sketchPath, defaultProfile)
4949
return instance, profile
5050
}
5151

@@ -64,13 +64,13 @@ func Create() (*rpc.Instance, error) {
6464
// Package and library indexes files are automatically updated if the
6565
// CLI is run for the first time.
6666
func Init(instance *rpc.Instance) {
67-
InitWithProfile(instance, "", nil)
67+
InitWithProfile(instance, "", nil, false)
6868
}
6969

7070
// InitWithProfile initializes instance by loading libraries and platforms specified in the given profile of the given sketch.
7171
// In case of loading failures return a list of errors for each platform or library that we failed to load.
7272
// Required Package and library indexes files are automatically downloaded.
73-
func InitWithProfile(instance *rpc.Instance, profileName string, sketchPath *paths.Path) *rpc.Profile {
73+
func InitWithProfile(instance *rpc.Instance, profileName string, sketchPath *paths.Path, defaultProfile bool) *rpc.Profile {
7474
// In case the CLI is executed for the first time
7575
if err := FirstUpdate(instance); err != nil {
7676
feedback.Warning(tr("Error initializing instance: %v", err))
@@ -84,6 +84,7 @@ func InitWithProfile(instance *rpc.Instance, profileName string, sketchPath *pat
8484
if sketchPath != nil {
8585
initReq.SketchPath = sketchPath.String()
8686
initReq.Profile = profileName
87+
initReq.DefaultProfile = defaultProfile
8788
}
8889
var profile *rpc.Profile
8990
err := commands.Init(initReq, func(res *rpc.InitResponse) {

0 commit comments

Comments
 (0)