|
| 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 | +} |
0 commit comments