Commit 8874d91b authored by Cristian Maglie's avatar Cristian Maglie

Moved tool Install/Download helpers from commands/core to commands

parent 6ec261e6
......@@ -26,7 +26,6 @@ import (
"github.com/arduino/arduino-cli/arduino/discovery"
"github.com/arduino/arduino-cli/cli"
"github.com/arduino/arduino-cli/commands"
"github.com/arduino/arduino-cli/commands/core"
"github.com/arduino/arduino-cli/common/formatter"
"github.com/arduino/arduino-cli/rpc"
)
......@@ -42,8 +41,8 @@ func BoardList(ctx context.Context, req *rpc.BoardListReq) (*rpc.BoardListResp,
serialDiscoveryTool, _ := getBuiltinSerialDiscoveryTool(pm)
if !serialDiscoveryTool.IsInstalled() {
formatter.Print("Downloading and installing missing tool: " + serialDiscoveryTool.String())
core.DownloadToolRelease(pm, serialDiscoveryTool, cli.OutputProgressBar())
core.InstallToolRelease(pm, serialDiscoveryTool, cli.OutputTaskProgress())
commands.DownloadToolRelease(pm, serialDiscoveryTool, cli.OutputProgressBar())
commands.InstallToolRelease(pm, serialDiscoveryTool, cli.OutputTaskProgress())
if err := pm.LoadHardware(cli.Config); err != nil {
formatter.PrintError(err, "Could not load hardware packages.")
......@@ -63,8 +62,7 @@ func BoardList(ctx context.Context, req *rpc.BoardListReq) (*rpc.BoardListResp,
}
// Find all installed discoveries
discoveries := discovery.ExtractDiscoveriesFromPlatforms(pm)
discoveries["serial"] = serialDiscovery
discoveries := append(discovery.ExtractDiscoveriesFromPlatforms(pm), serialDiscovery)
resp := &rpc.BoardListResp{Ports: []*rpc.DetectedPort{}}
for _, disc := range discoveries {
......
//
// This file is part of arduino-cli.
//
// Copyright 2018 ARDUINO SA (http://www.arduino.cc/)
//
// This software is released under the GNU General Public License version 3,
// which covers the main part of arduino-cli.
// The terms of this license can be found at:
// https://www.gnu.org/licenses/gpl-3.0.en.html
//
// You can be released from the requirements of the above licenses by purchasing
// a commercial license. Buying such a license is mandatory if you want to modify or
// otherwise use the software for commercial activities involving the Arduino
// software without disclosing the source code of your own applications. To purchase
// a commercial license, send an email to license@arduino.cc.
//
package commands
import (
"fmt"
"github.com/arduino/arduino-cli/arduino/cores"
"github.com/arduino/arduino-cli/arduino/cores/packagemanager"
"github.com/arduino/arduino-cli/rpc"
)
// DownloadToolRelease downloads a ToolRelease
func DownloadToolRelease(pm *packagemanager.PackageManager, toolRelease *cores.ToolRelease, downloadCB DownloadProgressCB) error {
resp, err := pm.DownloadToolRelease(toolRelease)
if err != nil {
return err
}
return Download(resp, toolRelease.String(), downloadCB)
}
// InstallToolRelease installs a ToolRelease
func InstallToolRelease(pm *packagemanager.PackageManager, toolRelease *cores.ToolRelease, taskCB TaskProgressCB) error {
log := pm.Log.WithField("Tool", toolRelease)
if toolRelease.IsInstalled() {
log.Warn("Tool already installed")
taskCB(&rpc.TaskProgress{Name: "Tool " + toolRelease.String() + " already installed", Completed: true})
return nil
}
log.Info("Installing tool")
taskCB(&rpc.TaskProgress{Name: "Installing " + toolRelease.String()})
err := pm.InstallTool(toolRelease)
if err != nil {
log.WithError(err).Warn("Cannot install tool")
return fmt.Errorf("installing tool %s: %s", toolRelease, err)
}
log.Info("Tool installed")
taskCB(&rpc.TaskProgress{Message: toolRelease.String() + " installed", Completed: true})
return nil
}
......@@ -17,7 +17,6 @@ import (
"github.com/arduino/arduino-cli/arduino/sketches"
"github.com/arduino/arduino-cli/cli"
"github.com/arduino/arduino-cli/commands"
"github.com/arduino/arduino-cli/commands/core"
"github.com/arduino/arduino-cli/rpc"
paths "github.com/arduino/go-paths-helper"
properties "github.com/arduino/go-properties-orderedmap"
......@@ -60,9 +59,9 @@ func Compile(ctx context.Context, req *rpc.CompileReq,
ctags, _ := getBuiltinCtagsTool(pm)
if !ctags.IsInstalled() {
taskCB(&rpc.TaskProgress{Name: "Downloading missing tool " + ctags.String()})
core.DownloadToolRelease(pm, ctags, downloadCB)
commands.DownloadToolRelease(pm, ctags, downloadCB)
taskCB(&rpc.TaskProgress{Completed: true})
core.InstallToolRelease(pm, ctags, taskCB)
commands.InstallToolRelease(pm, ctags, taskCB)
if err := pm.LoadHardware(cli.Config); err != nil {
return nil, fmt.Errorf("loading hardware packages: %s", err)
......
......@@ -78,14 +78,6 @@ func downloadTool(pm *packagemanager.PackageManager, tool *cores.ToolRelease, do
return fmt.Errorf("tool %s not available for the current OS", tool)
}
return DownloadToolRelease(pm, tool, downloadCB)
return commands.DownloadToolRelease(pm, tool, downloadCB)
}
// DownloadToolRelease downloads a ToolRelease
func DownloadToolRelease(pm *packagemanager.PackageManager, toolRelease *cores.ToolRelease, downloadCB commands.DownloadProgressCB) error {
resp, err := pm.DownloadToolRelease(toolRelease)
if err != nil {
return err
}
return commands.Download(resp, toolRelease.String(), downloadCB)
}
......@@ -94,7 +94,7 @@ func installPlatform(pm *packagemanager.PackageManager,
// Install tools first
for _, tool := range toolsToInstall {
err := InstallToolRelease(pm, tool, taskCB)
err := commands.InstallToolRelease(pm, tool, taskCB)
if err != nil {
// TODO: handle error
}
......@@ -141,26 +141,3 @@ func installPlatform(pm *packagemanager.PackageManager,
taskCB(&rpc.TaskProgress{Message: platformRelease.String() + " installed", Completed: true})
return nil
}
// InstallToolRelease installs a ToolRelease
func InstallToolRelease(pm *packagemanager.PackageManager, toolRelease *cores.ToolRelease, taskCB commands.TaskProgressCB) error {
log := pm.Log.WithField("Tool", toolRelease)
if toolRelease.IsInstalled() {
log.Warn("Tool already installed")
taskCB(&rpc.TaskProgress{Name: "Tool " + toolRelease.String() + " already installed", Completed: true})
return nil
}
log.Info("Installing tool")
taskCB(&rpc.TaskProgress{Name: "Installing " + toolRelease.String()})
err := pm.InstallTool(toolRelease)
if err != nil {
log.WithError(err).Warn("Cannot install tool")
return fmt.Errorf("installing tool %s: %s", toolRelease, err)
}
log.Info("Tool installed")
taskCB(&rpc.TaskProgress{Message: toolRelease.String() + " installed", Completed: true})
return nil
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment