Skip to content

Commit 5c3dc1d

Browse files
committed
Using cmp.Or helper
1 parent b3c5a39 commit 5c3dc1d

File tree

3 files changed

+6
-12
lines changed

3 files changed

+6
-12
lines changed

commands/service_profile_lib_add.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
package commands
1717

1818
import (
19+
"cmp"
1920
"context"
2021
"slices"
2122

@@ -37,10 +38,7 @@ func (s *arduinoCoreServerImpl) ProfileLibAdd(ctx context.Context, req *rpc.Prof
3738
}
3839

3940
// If no profile is specified, try to use the default one
40-
profileName := sk.Project.DefaultProfile
41-
if req.GetProfileName() != "" {
42-
profileName = req.GetProfileName()
43-
}
41+
profileName := cmp.Or(req.GetProfileName(), sk.Project.DefaultProfile)
4442
if profileName == "" {
4543
return nil, &cmderrors.MissingProfileError{}
4644
}

commands/service_profile_lib_list.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
package commands
1717

1818
import (
19+
"cmp"
1920
"context"
2021

2122
"github.com/arduino/arduino-cli/commands/cmderrors"
@@ -33,10 +34,7 @@ func (s *arduinoCoreServerImpl) ProfileLibList(ctx context.Context, req *rpc.Pro
3334
}
3435

3536
// If no profile is specified, try to use the default one
36-
profileName := sk.Project.DefaultProfile
37-
if req.GetProfileName() != "" {
38-
profileName = req.GetProfileName()
39-
}
37+
profileName := cmp.Or(req.GetProfileName(), sk.Project.DefaultProfile)
4038
if profileName == "" {
4139
return nil, &cmderrors.MissingProfileError{}
4240
}

commands/service_profile_lib_remove.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
package commands
1717

1818
import (
19+
"cmp"
1920
"context"
2021

2122
"github.com/arduino/arduino-cli/commands/cmderrors"
@@ -34,10 +35,7 @@ func (s *arduinoCoreServerImpl) ProfileLibRemove(ctx context.Context, req *rpc.P
3435
}
3536

3637
// If no profile is specified, try to use the default one
37-
profileName := sk.Project.DefaultProfile
38-
if req.GetProfileName() != "" {
39-
profileName = req.GetProfileName()
40-
}
38+
profileName := cmp.Or(req.GetProfileName(), sk.Project.DefaultProfile)
4139
if profileName == "" {
4240
return nil, &cmderrors.MissingProfileError{}
4341
}

0 commit comments

Comments
 (0)