Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit dbfdebd

Browse files
committed
Added profile lib-deps install
1 parent 58936ea commit dbfdebd

File tree

4 files changed

+738
-657
lines changed

4 files changed

+738
-657
lines changed

‎commands/service_profile_lib_add.go‎

Lines changed: 45 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,11 @@ import (
2020

2121
"github.com/arduino/arduino-cli/commands/cmderrors"
2222
"github.com/arduino/arduino-cli/commands/internal/instances"
23+
"github.com/arduino/arduino-cli/internal/arduino/libraries/librariesindex"
2324
"github.com/arduino/arduino-cli/internal/arduino/sketch"
2425
rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1"
2526
paths "github.com/arduino/go-paths-helper"
27+
"go.bug.st/f"
2628
)
2729

2830
// ProfileLibAdd adds a library to the specified profile or to the default profile.
@@ -48,15 +50,17 @@ func (s *arduinoCoreServerImpl) ProfileLibAdd(ctx context.Context, req *rpc.Prof
4850
return nil, err
4951
}
5052

51-
var addedLib *sketch.ProfileLibraryReference
53+
var addedLibs []*sketch.ProfileLibraryReference
54+
var skippedLibs []*sketch.ProfileLibraryReference
5255
if reqLocalLib := req.GetLibrary().GetLocalLibrary(); reqLocalLib != nil {
5356
// Add a local library
5457
path := paths.New(reqLocalLib.GetPath())
5558
if path == nil {
5659
return nil, &cmderrors.InvalidArgumentError{Message: "invalid library path"}
5760
}
58-
addedLib = &sketch.ProfileLibraryReference{InstallDir: path}
61+
addedLib := &sketch.ProfileLibraryReference{InstallDir: path}
5962
profile.Libraries = append(profile.Libraries, addedLib)
63+
addedLibs = append(addedLibs, addedLib)
6064
} else if reqIndexLib := req.GetLibrary().GetIndexLibrary(); reqIndexLib != nil {
6165
// Obtain the library index from the manager
6266
li, err := instances.GetLibrariesIndex(req.GetInstance())
@@ -71,16 +75,41 @@ func (s *arduinoCoreServerImpl) ProfileLibAdd(ctx context.Context, req *rpc.Prof
7175
if err != nil {
7276
return nil, err
7377
}
74-
// If the library has been already added to the profile, just update the version
75-
if lib, _ := profile.GetLibrary(reqIndexLib.GetName()); lib != nil {
76-
lib.Version = libRelease.GetVersion()
77-
addedLib = lib
78-
} else {
79-
addedLib = &sketch.ProfileLibraryReference{
80-
Library: reqIndexLib.GetName(),
81-
Version: libRelease.GetVersion(),
78+
79+
add := func(libReleaseToAdd *librariesindex.Release) {
80+
libRefToAdd := &sketch.ProfileLibraryReference{
81+
Library: libReleaseToAdd.GetName(),
82+
Version: libReleaseToAdd.GetVersion(),
83+
}
84+
existingLibRef, _ := profile.GetLibrary(libReleaseToAdd.GetName())
85+
if existingLibRef == nil {
86+
profile.Libraries = append(profile.Libraries, libRefToAdd)
87+
addedLibs = append(addedLibs, libRefToAdd)
88+
}
89+
// If the library has been already added to the profile, just update the version
90+
if req.GetNoOverwrite() {
91+
skippedLibs = append(skippedLibs, libRefToAdd)
92+
return
93+
}
94+
existingLibRef.Version = libReleaseToAdd.GetVersion()
95+
addedLibs = append(addedLibs, existingLibRef)
96+
}
97+
98+
add(libRelease)
99+
100+
if req.GetAddDependencies() {
101+
lme, release, err := instances.GetLibraryManagerExplorer(req.GetInstance())
102+
if err != nil {
103+
return nil, err
104+
}
105+
deps, err := libraryResolveDependencies(lme, li, libRelease.GetName(), libRelease.GetVersion().String(), false)
106+
release()
107+
if err != nil {
108+
return nil, err
109+
}
110+
for _, d := range deps {
111+
add(d)
82112
}
83-
profile.Libraries = append(profile.Libraries, addedLib)
84113
}
85114
} else {
86115
return nil, &cmderrors.InvalidArgumentError{Message: "library must be specified"}
@@ -91,5 +120,9 @@ func (s *arduinoCoreServerImpl) ProfileLibAdd(ctx context.Context, req *rpc.Prof
91120
return nil, err
92121
}
93122

94-
return &rpc.ProfileLibAddResponse{Library: addedLib.ToRpc(), ProfileName: profileName}, nil
123+
return &rpc.ProfileLibAddResponse{
124+
AddedLibraries: f.Map(addedLibs, (*sketch.ProfileLibraryReference).ToRpc),
125+
SkippedLibraries: f.Map(skippedLibs, (*sketch.ProfileLibraryReference).ToRpc),
126+
ProfileName: profileName,
127+
}, nil
95128
}

‎internal/cli/profile/lib.go‎

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import (
2828
"github.com/arduino/arduino-cli/internal/i18n"
2929
rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1"
3030
"github.com/spf13/cobra"
31+
"go.bug.st/f"
3132
)
3233

3334
func initLibCommand(srv rpc.ArduinoCoreServiceServer) *cobra.Command {
@@ -96,9 +97,12 @@ func runLibAddCommand(ctx context.Context, args []string, srv rpc.ArduinoCoreSer
9697
if err != nil {
9798
feedback.Fatal(i18n.Tr("Error adding %s to the profile %s: %v", lib.Name, profileArg.Get(), err), feedback.ErrGeneric)
9899
}
100+
added := f.Map(resp.GetAddedLibraries(), func(l *rpc.ProfileLibraryReference) *result.ProfileLibraryReference_IndexLibraryResult {
101+
return result.NewProfileLibraryReference_IndexLibraryResult(l.GetIndexLibrary())
102+
})
99103
feedback.PrintResult(libAddResult{
100-
Library: result.NewProfileLibraryReference_IndexLibraryResult(resp.GetLibrary().GetIndexLibrary()),
101-
ProfileName: resp.ProfileName})
104+
AddedLibraries: added,
105+
ProfileName: resp.ProfileName})
102106
}
103107
}
104108

@@ -158,16 +162,24 @@ func runLibRemoveCommand(ctx context.Context, args []string, srv rpc.ArduinoCore
158162
}
159163

160164
type libAddResult struct {
161-
Library *result.ProfileLibraryReference_IndexLibraryResult `json:"library"`
162-
ProfileName string `json:"profile_name"`
165+
AddedLibraries []*result.ProfileLibraryReference_IndexLibraryResult `json:"added_libraries"`
166+
SkippedLibraries []*result.ProfileLibraryReference_IndexLibraryResult `json:"skipped_libraries"`
167+
ProfileName string `json:"profile_name"`
163168
}
164169

165170
func (lr libAddResult) Data() interface{} {
166171
return lr
167172
}
168173

169174
func (lr libAddResult) String() string {
170-
return i18n.Tr("Profile %s: %s@%s added successfully", lr.ProfileName, lr.Library.Name, lr.Library.Version)
175+
res := ""
176+
if len(lr.AddedLibraries) > 0 {
177+
res += fmt.Sprintln(i18n.Tr("The following libraries were added to the profile %s:", lr.ProfileName))
178+
for _, l := range lr.AddedLibraries {
179+
res += fmt.Sprintf(" - %s@%s\n", l.Name, l.Version)
180+
}
181+
}
182+
return res
171183
}
172184

173185
type libRemoveResult struct {

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /