Skip to content

Commit f6b75c2

Browse files
committed
Cleaned up all 'core' commands/cli modules
1 parent c11c8bd commit f6b75c2

13 files changed

+84
-41
lines changed

cli/core/install.go

+7-8
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,11 @@ package core
1919

2020
import (
2121
"context"
22+
"os"
2223

2324
"github.com/arduino/arduino-cli/cli"
2425
"github.com/arduino/arduino-cli/commands/core"
26+
"github.com/arduino/arduino-cli/common/formatter"
2527
"github.com/arduino/arduino-cli/output"
2628
"github.com/arduino/arduino-cli/rpc"
2729
"github.com/sirupsen/logrus"
@@ -50,18 +52,15 @@ func runInstallCommand(cmd *cobra.Command, args []string) {
5052
platformsRefs := parsePlatformReferenceArgs(args)
5153

5254
for _, platformRef := range platformsRefs {
53-
core.PlatformInstall(context.Background(), &rpc.PlatformInstallReq{
55+
_, err := core.PlatformInstall(context.Background(), &rpc.PlatformInstallReq{
5456
Instance: instance,
5557
PlatformPackage: platformRef.Package,
5658
Architecture: platformRef.PlatformArchitecture,
5759
Version: platformRef.PlatformVersion.String(),
5860
}, output.DownloadProgressBar(), output.NewTaskProgressCB())
59-
// if err != nil {
60-
// formatter.PrintError(err, "Error during build")
61-
// os.Exit(cli.ErrGeneric)
62-
// }
63-
// }
61+
if err != nil {
62+
formatter.PrintError(err, "Error during install")
63+
os.Exit(cli.ErrGeneric)
64+
}
6465
}
65-
66-
// TODO: Cleanup unused tools
6766
}

cli/core/list.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import (
2828
"github.com/arduino/arduino-cli/common/formatter"
2929
"github.com/arduino/arduino-cli/output"
3030
"github.com/arduino/arduino-cli/rpc"
31+
"github.com/sirupsen/logrus"
3132
"github.com/spf13/cobra"
3233
)
3334

@@ -50,12 +51,14 @@ var listFlags struct {
5051

5152
func runListCommand(cmd *cobra.Command, args []string) {
5253
instance := cli.CreateInstance()
54+
logrus.Info("Executing `arduino core list`")
55+
5356
resp, err := core.PlatformList(context.Background(), &rpc.PlatformListReq{
5457
Instance: instance,
5558
UpdatableOnly: listFlags.updatableOnly,
5659
})
5760
if err != nil {
58-
formatter.PrintError(err, "Error saerching for platforms")
61+
formatter.PrintError(err, "Error listing platforms")
5962
os.Exit(cli.ErrGeneric)
6063
}
6164
installed := resp.GetInstalledPlatform()

cli/core/search.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import (
2222
"fmt"
2323
"os"
2424
"sort"
25-
2625
"strings"
2726

2827
"github.com/arduino/arduino-cli/cli"
@@ -47,11 +46,12 @@ func initSearchCommand() *cobra.Command {
4746
}
4847

4948
func runSearchCommand(cmd *cobra.Command, args []string) {
50-
logrus.Info("Executing `arduino core search`")
5149
instance := cli.CreateInstance()
52-
arguments := strings.ToLower(strings.Join(args, " "))
50+
logrus.Info("Executing `arduino core search`")
5351

52+
arguments := strings.ToLower(strings.Join(args, " "))
5453
formatter.Print("Searching for platforms matching '" + arguments + "'")
54+
5555
resp, err := core.PlatformSearch(context.Background(), &rpc.PlatformSearchReq{
5656
Instance: instance,
5757
SearchArgs: arguments,

cli/core/uninstall.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ func initUninstallCommand() *cobra.Command {
4141

4242
func runUninstallCommand(cmd *cobra.Command, args []string) {
4343
instance := cli.CreateInstance()
44-
logrus.Info("Executing `arduino core download`")
44+
logrus.Info("Executing `arduino core uninstall`")
4545

4646
platformsRefs := parsePlatformReferenceArgs(args)
4747

cli/core/update_index.go

+10-2
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,14 @@ package core
1919

2020
import (
2121
"context"
22+
"os"
2223

2324
"github.com/arduino/arduino-cli/cli"
2425
"github.com/arduino/arduino-cli/commands"
26+
"github.com/arduino/arduino-cli/common/formatter"
2527
"github.com/arduino/arduino-cli/output"
2628
"github.com/arduino/arduino-cli/rpc"
29+
"github.com/sirupsen/logrus"
2730
"github.com/spf13/cobra"
2831
)
2932

@@ -41,8 +44,13 @@ func initUpdateIndexCommand() *cobra.Command {
4144

4245
func runUpdateIndexCommand(cmd *cobra.Command, args []string) {
4346
instance := cli.CreateInstance()
44-
commands.UpdateIndex(context.Background(), &rpc.UpdateIndexReq{
47+
logrus.Info("Executing `arduino core update-index`")
48+
49+
_, err := commands.UpdateIndex(context.Background(), &rpc.UpdateIndexReq{
4550
Instance: instance,
4651
}, output.DownloadProgressBar())
47-
52+
if err != nil {
53+
formatter.PrintError(err, "Error during install")
54+
os.Exit(cli.ErrGeneric)
55+
}
4856
}

cli/core/upgrade.go

+7-1
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,11 @@ package core
1919

2020
import (
2121
"context"
22+
"os"
2223

2324
"github.com/arduino/arduino-cli/cli"
2425
"github.com/arduino/arduino-cli/commands/core"
26+
"github.com/arduino/arduino-cli/common/formatter"
2527
"github.com/arduino/arduino-cli/output"
2628
"github.com/arduino/arduino-cli/rpc"
2729
"github.com/sirupsen/logrus"
@@ -49,11 +51,15 @@ func runUpgradeCommand(cmd *cobra.Command, args []string) {
4951

5052
platformsRefs := parsePlatformReferenceArgs(args)
5153
for _, platformRef := range platformsRefs {
52-
core.PlatformUpgrade(context.Background(), &rpc.PlatformUpgradeReq{
54+
_, err := core.PlatformUpgrade(context.Background(), &rpc.PlatformUpgradeReq{
5355
Instance: instance,
5456
PlatformPackage: platformRef.Package,
5557
Architecture: platformRef.PlatformArchitecture,
5658
Version: platformRef.PlatformVersion.String(),
5759
}, output.DownloadProgressBar(), output.NewTaskProgressCB())
60+
if err != nil {
61+
formatter.PrintError(err, "Error during upgrade")
62+
os.Exit(cli.ErrGeneric)
63+
}
5864
}
5965
}

commands/core/download.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -30,18 +30,18 @@ import (
3030
)
3131

3232
func PlatformDownload(ctx context.Context, req *rpc.PlatformDownloadReq, downloadCB commands.DownloadProgressCB) (*rpc.PlatformDownloadResp, error) {
33+
pm := commands.GetPackageManager(req)
34+
if pm == nil {
35+
return nil, errors.New("invalid instance")
36+
}
37+
3338
var version *semver.Version
3439
if v, err := semver.Parse(req.Version); err == nil {
3540
version = v
3641
} else {
3742
return nil, fmt.Errorf("invalid version: %s", err)
3843
}
3944

40-
pm := commands.GetPackageManager(req)
41-
if pm == nil {
42-
return nil, errors.New("invalid instance")
43-
}
44-
4545
platform, tools, err := pm.FindPlatformReleaseDependencies(&packagemanager.PlatformReference{
4646
Package: req.PlatformPackage,
4747
PlatformArchitecture: req.Architecture,

commands/core/install.go

+24-9
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,20 @@
1+
/*
2+
* This file is part of arduino-cli.
3+
*
4+
* Copyright 2018 ARDUINO SA (http://www.arduino.cc/)
5+
*
6+
* This software is released under the GNU General Public License version 3,
7+
* which covers the main part of arduino-cli.
8+
* The terms of this license can be found at:
9+
* https://www.gnu.org/licenses/gpl-3.0.en.html
10+
*
11+
* You can be released from the requirements of the above licenses by purchasing
12+
* a commercial license. Buying such a license is mandatory if you want to modify or
13+
* otherwise use the software for commercial activities involving the Arduino
14+
* software without disclosing the source code of your own applications. To purchase
15+
* a commercial license, send an email to license@arduino.cc.
16+
*/
17+
118
package core
219

320
import (
@@ -8,13 +25,18 @@ import (
825
"github.com/arduino/arduino-cli/arduino/cores"
926
"github.com/arduino/arduino-cli/arduino/cores/packagemanager"
1027
"github.com/arduino/arduino-cli/commands"
11-
"github.com/arduino/arduino-cli/common/formatter"
1228
"github.com/arduino/arduino-cli/rpc"
1329
semver "go.bug.st/relaxed-semver"
1430
)
1531

1632
func PlatformInstall(ctx context.Context, req *rpc.PlatformInstallReq,
1733
downloadCB commands.DownloadProgressCB, taskCB commands.TaskProgressCB) (*rpc.PlatformInstallResp, error) {
34+
35+
pm := commands.GetPackageManager(req)
36+
if pm == nil {
37+
return nil, errors.New("invalid instance")
38+
}
39+
1840
var version *semver.Version
1941
if req.Version != "" {
2042
if v, err := semver.Parse(req.Version); err == nil {
@@ -24,11 +46,6 @@ func PlatformInstall(ctx context.Context, req *rpc.PlatformInstallReq,
2446
}
2547
}
2648

27-
pm := commands.GetPackageManager(req)
28-
if pm == nil {
29-
return nil, errors.New("invalid instance")
30-
}
31-
3249
platform, tools, err := pm.FindPlatformReleaseDependencies(&packagemanager.PlatformReference{
3350
Package: req.PlatformPackage,
3451
PlatformArchitecture: req.Architecture,
@@ -119,7 +136,6 @@ func installPlatform(pm *packagemanager.PackageManager,
119136
if err := pm.UninstallPlatform(platformRelease); err != nil {
120137
log.WithError(err).Error("Error rolling-back changes.")
121138
taskCB(&rpc.TaskProgress{Message: "Error rolling-back changes: " + err.Error()})
122-
//return fmt.Errorf("rolling-back changes: %s", err)
123139
}
124140

125141
return fmt.Errorf("updating platform: %s", errUn)
@@ -146,8 +162,7 @@ func InstallToolRelease(pm *packagemanager.PackageManager, toolRelease *cores.To
146162
err := pm.InstallTool(toolRelease)
147163
if err != nil {
148164
log.WithError(err).Warn("Cannot install tool")
149-
formatter.PrintError(err, "Cannot install tool: "+toolRelease.String())
150-
return fmt.Errorf("Cannot install tool: "+toolRelease.String(), err)
165+
return fmt.Errorf("installing tool %s: %s", toolRelease, err)
151166
}
152167
log.Info("Tool installed")
153168
taskCB(&rpc.TaskProgress{Message: toolRelease.String() + " installed", Completed: true})

commands/core/list.go

+5
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,18 @@ package core
1919

2020
import (
2121
"context"
22+
"errors"
2223

2324
"github.com/arduino/arduino-cli/commands"
2425
"github.com/arduino/arduino-cli/rpc"
2526
)
2627

2728
func PlatformList(ctx context.Context, req *rpc.PlatformListReq) (*rpc.PlatformListResp, error) {
2829
pm := commands.GetPackageManager(req)
30+
if pm == nil {
31+
return nil, errors.New("invalid instance")
32+
}
33+
2934
installed := []*rpc.InstalledPlatform{}
3035
for _, targetPackage := range pm.GetPackages().Packages {
3136
for _, platform := range targetPackage.Platforms {

commands/core/search.go

+5-2
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,20 @@ package core
1919

2020
import (
2121
"context"
22+
"errors"
2223
"regexp"
2324
"strings"
2425

26+
"github.com/arduino/arduino-cli/arduino/cores"
2527
"github.com/arduino/arduino-cli/commands"
2628
"github.com/arduino/arduino-cli/rpc"
27-
28-
"github.com/arduino/arduino-cli/arduino/cores"
2929
)
3030

3131
func PlatformSearch(ctx context.Context, req *rpc.PlatformSearchReq) (*rpc.PlatformSearchResp, error) {
3232
pm := commands.GetPackageManager(req)
33+
if pm == nil {
34+
return nil, errors.New("invalid instance")
35+
}
3336

3437
search := req.SearchArgs
3538

commands/core/uninstall.go

+6-4
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,17 @@ import (
3030
)
3131

3232
func PlatformUninstall(ctx context.Context, req *rpc.PlatformUninstallReq, taskCB commands.TaskProgressCB) (*rpc.PlatformUninstallResp, error) {
33+
pm := commands.GetPackageManager(req)
34+
if pm == nil {
35+
return nil, errors.New("invalid instance")
36+
}
37+
3338
// If no version is specified consider the installed
3439
version, err := semver.Parse(req.Version)
3540
if err != nil {
3641
return nil, fmt.Errorf("invalid version: %s", err)
3742
}
38-
pm := commands.GetPackageManager(req)
39-
if pm == nil {
40-
return nil, errors.New("invalid instance")
41-
}
43+
4244
ref := &packagemanager.PlatformReference{
4345
Package: req.PlatformPackage,
4446
PlatformArchitecture: req.Architecture,

commands/core/upgrade.go

+6-4
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,12 @@ import (
3030

3131
func PlatformUpgrade(ctx context.Context, req *rpc.PlatformUpgradeReq,
3232
downloadCB commands.DownloadProgressCB, taskCB commands.TaskProgressCB) (*rpc.PlatformUpgradeResp, error) {
33+
34+
pm := commands.GetPackageManager(req)
35+
if pm == nil {
36+
return nil, errors.New("invalid instance")
37+
}
38+
3339
// Extract all PlatformReference to platforms that have updates
3440
var version *semver.Version
3541
if req.Version != "" {
@@ -39,10 +45,6 @@ func PlatformUpgrade(ctx context.Context, req *rpc.PlatformUpgradeReq,
3945
return nil, fmt.Errorf("invalid version: %s", err)
4046
}
4147
}
42-
pm := commands.GetPackageManager(req)
43-
if pm == nil {
44-
return nil, errors.New("invalid instance")
45-
}
4648

4749
ref := &packagemanager.PlatformReference{
4850
Package: req.PlatformPackage,

commands/instances.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -136,10 +136,10 @@ func UpdateLibrariesIndex(ctx context.Context, lm *librariesmanager.LibrariesMan
136136
func UpdateIndex(ctx context.Context, req *rpc.UpdateIndexReq, downloadCB DownloadProgressCB) (*rpc.UpdateIndexResp, error) {
137137
id := req.Instance.Id
138138
coreInstance, ok := instances[id]
139-
140139
if !ok {
141140
return nil, fmt.Errorf("invalid handle")
142141
}
142+
143143
indexpath := coreInstance.config.IndexesDir()
144144
for _, URL := range coreInstance.config.BoardManagerAdditionalUrls {
145145
logrus.WithField("url", URL).Print("Updating index")

0 commit comments

Comments
 (0)