Skip to content

Commit 6873b6a

Browse files
committed
Moved tool Install/Download helpers from commands/core to commands
1 parent d42bddf commit 6873b6a

File tree

5 files changed

+65
-41
lines changed

5 files changed

+65
-41
lines changed

commands/board/list.go

+3-5
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ import (
2626
"github.com/arduino/arduino-cli/arduino/discovery"
2727
"github.com/arduino/arduino-cli/cli"
2828
"github.com/arduino/arduino-cli/commands"
29-
"github.com/arduino/arduino-cli/commands/core"
3029
"github.com/arduino/arduino-cli/common/formatter"
3130
"github.com/arduino/arduino-cli/rpc"
3231
)
@@ -42,8 +41,8 @@ func BoardList(ctx context.Context, req *rpc.BoardListReq) (*rpc.BoardListResp,
4241
serialDiscoveryTool, _ := getBuiltinSerialDiscoveryTool(pm)
4342
if !serialDiscoveryTool.IsInstalled() {
4443
formatter.Print("Downloading and installing missing tool: " + serialDiscoveryTool.String())
45-
core.DownloadToolRelease(pm, serialDiscoveryTool, cli.OutputProgressBar())
46-
core.InstallToolRelease(pm, serialDiscoveryTool, cli.OutputTaskProgress())
44+
commands.DownloadToolRelease(pm, serialDiscoveryTool, cli.OutputProgressBar())
45+
commands.InstallToolRelease(pm, serialDiscoveryTool, cli.OutputTaskProgress())
4746

4847
if err := pm.LoadHardware(cli.Config); err != nil {
4948
formatter.PrintError(err, "Could not load hardware packages.")
@@ -63,8 +62,7 @@ func BoardList(ctx context.Context, req *rpc.BoardListReq) (*rpc.BoardListResp,
6362
}
6463

6564
// Find all installed discoveries
66-
discoveries := discovery.ExtractDiscoveriesFromPlatforms(pm)
67-
discoveries["serial"] = serialDiscovery
65+
discoveries := append(discovery.ExtractDiscoveriesFromPlatforms(pm), serialDiscovery)
6866

6967
resp := &rpc.BoardListResp{Ports: []*rpc.DetectedPort{}}
7068
for _, disc := range discoveries {

commands/bundled_tools.go

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
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 [email protected].
16+
//
17+
18+
package commands
19+
20+
import (
21+
"fmt"
22+
23+
"github.com/arduino/arduino-cli/arduino/cores"
24+
"github.com/arduino/arduino-cli/arduino/cores/packagemanager"
25+
"github.com/arduino/arduino-cli/rpc"
26+
)
27+
28+
// DownloadToolRelease downloads a ToolRelease
29+
func DownloadToolRelease(pm *packagemanager.PackageManager, toolRelease *cores.ToolRelease, downloadCB DownloadProgressCB) error {
30+
resp, err := pm.DownloadToolRelease(toolRelease)
31+
if err != nil {
32+
return err
33+
}
34+
return Download(resp, toolRelease.String(), downloadCB)
35+
}
36+
37+
// InstallToolRelease installs a ToolRelease
38+
func InstallToolRelease(pm *packagemanager.PackageManager, toolRelease *cores.ToolRelease, taskCB TaskProgressCB) error {
39+
log := pm.Log.WithField("Tool", toolRelease)
40+
41+
if toolRelease.IsInstalled() {
42+
log.Warn("Tool already installed")
43+
taskCB(&rpc.TaskProgress{Name: "Tool " + toolRelease.String() + " already installed", Completed: true})
44+
return nil
45+
}
46+
47+
log.Info("Installing tool")
48+
taskCB(&rpc.TaskProgress{Name: "Installing " + toolRelease.String()})
49+
err := pm.InstallTool(toolRelease)
50+
if err != nil {
51+
log.WithError(err).Warn("Cannot install tool")
52+
return fmt.Errorf("installing tool %s: %s", toolRelease, err)
53+
}
54+
log.Info("Tool installed")
55+
taskCB(&rpc.TaskProgress{Message: toolRelease.String() + " installed", Completed: true})
56+
57+
return nil
58+
}

commands/compile/compile.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ import (
1717
"github.com/arduino/arduino-cli/arduino/sketches"
1818
"github.com/arduino/arduino-cli/cli"
1919
"github.com/arduino/arduino-cli/commands"
20-
"github.com/arduino/arduino-cli/commands/core"
2120
"github.com/arduino/arduino-cli/rpc"
2221
paths "github.com/arduino/go-paths-helper"
2322
properties "github.com/arduino/go-properties-orderedmap"
@@ -60,9 +59,9 @@ func Compile(ctx context.Context, req *rpc.CompileReq,
6059
ctags, _ := getBuiltinCtagsTool(pm)
6160
if !ctags.IsInstalled() {
6261
taskCB(&rpc.TaskProgress{Name: "Downloading missing tool " + ctags.String()})
63-
core.DownloadToolRelease(pm, ctags, downloadCB)
62+
commands.DownloadToolRelease(pm, ctags, downloadCB)
6463
taskCB(&rpc.TaskProgress{Completed: true})
65-
core.InstallToolRelease(pm, ctags, taskCB)
64+
commands.InstallToolRelease(pm, ctags, taskCB)
6665

6766
if err := pm.LoadHardware(cli.Config); err != nil {
6867
return nil, fmt.Errorf("loading hardware packages: %s", err)

commands/core/download.go

+1-9
Original file line numberDiff line numberDiff line change
@@ -78,14 +78,6 @@ func downloadTool(pm *packagemanager.PackageManager, tool *cores.ToolRelease, do
7878
return fmt.Errorf("tool %s not available for the current OS", tool)
7979
}
8080

81-
return DownloadToolRelease(pm, tool, downloadCB)
81+
return commands.DownloadToolRelease(pm, tool, downloadCB)
8282
}
8383

84-
// DownloadToolRelease downloads a ToolRelease
85-
func DownloadToolRelease(pm *packagemanager.PackageManager, toolRelease *cores.ToolRelease, downloadCB commands.DownloadProgressCB) error {
86-
resp, err := pm.DownloadToolRelease(toolRelease)
87-
if err != nil {
88-
return err
89-
}
90-
return commands.Download(resp, toolRelease.String(), downloadCB)
91-
}

commands/core/install.go

+1-24
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ func installPlatform(pm *packagemanager.PackageManager,
9494

9595
// Install tools first
9696
for _, tool := range toolsToInstall {
97-
err := InstallToolRelease(pm, tool, taskCB)
97+
err := commands.InstallToolRelease(pm, tool, taskCB)
9898
if err != nil {
9999
// TODO: handle error
100100
}
@@ -141,26 +141,3 @@ func installPlatform(pm *packagemanager.PackageManager,
141141
taskCB(&rpc.TaskProgress{Message: platformRelease.String() + " installed", Completed: true})
142142
return nil
143143
}
144-
145-
// InstallToolRelease installs a ToolRelease
146-
func InstallToolRelease(pm *packagemanager.PackageManager, toolRelease *cores.ToolRelease, taskCB commands.TaskProgressCB) error {
147-
log := pm.Log.WithField("Tool", toolRelease)
148-
149-
if toolRelease.IsInstalled() {
150-
log.Warn("Tool already installed")
151-
taskCB(&rpc.TaskProgress{Name: "Tool " + toolRelease.String() + " already installed", Completed: true})
152-
return nil
153-
}
154-
155-
log.Info("Installing tool")
156-
taskCB(&rpc.TaskProgress{Name: "Installing " + toolRelease.String()})
157-
err := pm.InstallTool(toolRelease)
158-
if err != nil {
159-
log.WithError(err).Warn("Cannot install tool")
160-
return fmt.Errorf("installing tool %s: %s", toolRelease, err)
161-
}
162-
log.Info("Tool installed")
163-
taskCB(&rpc.TaskProgress{Message: toolRelease.String() + " installed", Completed: true})
164-
165-
return nil
166-
}

0 commit comments

Comments
 (0)