Skip to content

Commit 2aa7e32

Browse files
committed
Using cmp.Or helper
1 parent 3a14601 commit 2aa7e32

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
"slices"
2122

@@ -36,10 +37,7 @@ func (s *arduinoCoreServerImpl) ProfileLibRemove(ctx context.Context, req *rpc.P
3637
}
3738

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

0 commit comments

Comments
 (0)