Skip to content

Commit 3f3df93

Browse files
committed
no need to pass around the whole request object
1 parent 6e7e8d1 commit 3f3df93

File tree

8 files changed

+18
-16
lines changed

8 files changed

+18
-16
lines changed

cli/lib/upgrade.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,14 @@ func initUpgradeCommand() *cobra.Command {
4848
func runUpgradeCommand(cmd *cobra.Command, args []string) {
4949
instance := instance.CreateInstaceIgnorePlatformIndexErrors()
5050

51-
err := lib.LibraryUpgradeAll(context.Background(), &rpc.LibraryUpgradeAllReq{
52-
Instance: instance,
53-
}, output.ProgressBar(), output.TaskProgress(), globals.HTTPClientHeader)
54-
if err != nil {
55-
formatter.PrintError(err, "Error upgrading libraries")
56-
os.Exit(errorcodes.ErrGeneric)
51+
if len(args) == 0 {
52+
err := lib.LibraryUpgradeAll(context.Background(), &rpc.LibraryUpgradeAllReq{
53+
Instance: instance,
54+
}, output.ProgressBar(), output.TaskProgress(), globals.HTTPClientHeader)
55+
if err != nil {
56+
formatter.PrintError(err, "Error upgrading libraries")
57+
os.Exit(errorcodes.ErrGeneric)
58+
}
5759
}
5860

5961
logrus.Info("Done")

commands/instances.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,9 @@ func GetPackageManager(req InstanceContainer) *packagemanager.PackageManager {
7575
return i.PackageManager
7676
}
7777

78-
// GetLibraryManager FIXMEDOC
79-
func GetLibraryManager(req InstanceContainer) *librariesmanager.LibrariesManager {
80-
i, ok := instances[req.GetInstance().GetId()]
78+
// GetLibraryManager returns the library manager for the given instance ID
79+
func GetLibraryManager(instanceID int32) *librariesmanager.LibrariesManager {
80+
i, ok := instances[instanceID]
8181
if !ok {
8282
return nil
8383
}
@@ -231,7 +231,7 @@ func Destroy(ctx context.Context, req *rpc.DestroyReq) (*rpc.DestroyResp, error)
231231
// UpdateLibrariesIndex updates the library_index.json
232232
func UpdateLibrariesIndex(ctx context.Context, req *rpc.UpdateLibrariesIndexReq, downloadCB func(*rpc.DownloadProgress)) error {
233233
logrus.Info("Updating libraries index")
234-
lm := GetLibraryManager(req)
234+
lm := GetLibraryManager(req.GetInstance().GetId())
235235
if lm == nil {
236236
return fmt.Errorf("invalid handle")
237237
}

commands/lib/download.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ func LibraryDownload(ctx context.Context, req *rpc.LibraryDownloadReq, downloadC
3434
downloaderHeaders http.Header) (*rpc.LibraryDownloadResp, error) {
3535
logrus.Info("Executing `arduino lib download`")
3636

37-
lm := commands.GetLibraryManager(req)
37+
lm := commands.GetLibraryManager(req.GetInstance().GetId())
3838

3939
logrus.Info("Preparing download")
4040

commands/lib/install.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ import (
3333
func LibraryInstall(ctx context.Context, req *rpc.LibraryInstallReq,
3434
downloadCB commands.DownloadProgressCB, taskCB commands.TaskProgressCB, downloaderHeaders http.Header) error {
3535

36-
lm := commands.GetLibraryManager(req)
36+
lm := commands.GetLibraryManager(req.GetInstance().GetId())
3737

3838
libRelease, err := findLibraryIndexRelease(lm, req)
3939
if err != nil {

commands/lib/list.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ type installedLib struct {
3434

3535
// LibraryList FIXMEDOC
3636
func LibraryList(ctx context.Context, req *rpc.LibraryListReq) (*rpc.LibraryListResp, error) {
37-
lm := commands.GetLibraryManager(req)
37+
lm := commands.GetLibraryManager(req.GetInstance().GetId())
3838

3939
instaledLib := []*rpc.InstalledLibrary{}
4040
res := listLibraries(lm, req.GetUpdatable(), req.GetAll())

commands/lib/search.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import (
2929

3030
// LibrarySearch FIXMEDOC
3131
func LibrarySearch(ctx context.Context, req *rpc.LibrarySearchReq) (*rpc.LibrarySearchResp, error) {
32-
lm := commands.GetLibraryManager(req)
32+
lm := commands.GetLibraryManager(req.GetInstance().GetId())
3333
if lm == nil {
3434
return nil, errors.New("invalid instance")
3535
}

commands/lib/uninstall.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import (
2727

2828
// LibraryUninstall FIXMEDOC
2929
func LibraryUninstall(ctx context.Context, req *rpc.LibraryUninstallReq, taskCB commands.TaskProgressCB) error {
30-
lm := commands.GetLibraryManager(req)
30+
lm := commands.GetLibraryManager(req.GetInstance().GetId())
3131
ref, err := createLibIndexReference(lm, req)
3232
if err != nil {
3333
return err

commands/lib/upgrade.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import (
2929
// LibraryUpgradeAll FIXMEDOC
3030
func LibraryUpgradeAll(ctx context.Context, req *rpc.LibraryUpgradeAllReq, downloadCB commands.DownloadProgressCB,
3131
taskCB commands.TaskProgressCB, downloaderHeaders http.Header) error {
32-
lm := commands.GetLibraryManager(req)
32+
lm := commands.GetLibraryManager(req.GetInstance().GetId())
3333

3434
// Obtain the list of upgradable libraries
3535
list := listLibraries(lm, true, true)

0 commit comments

Comments
 (0)