18
18
package core
19
19
20
20
import (
21
- "os "
21
+ "context "
22
22
23
- "go.bug.st/downloader"
24
-
25
- "github.com/arduino/arduino-cli/arduino/cores"
26
- "github.com/arduino/arduino-cli/arduino/cores/packagemanager"
27
23
"github.com/arduino/arduino-cli/cli"
28
- "github.com/arduino/arduino-cli/common/formatter"
24
+ "github.com/arduino/arduino-cli/commands/core"
25
+ "github.com/arduino/arduino-cli/rpc"
29
26
"github.com/sirupsen/logrus"
30
27
"github.com/spf13/cobra"
31
28
)
@@ -45,62 +42,16 @@ func initDownloadCommand() *cobra.Command {
45
42
}
46
43
47
44
func runDownloadCommand (cmd * cobra.Command , args []string ) {
45
+ instance := cli .CreateInstance ()
48
46
logrus .Info ("Executing `arduino core download`" )
49
47
50
48
platformsRefs := parsePlatformReferenceArgs (args )
51
- pm , _ := cli .InitPackageAndLibraryManagerWithoutBundles ()
52
49
for _ , platformRef := range platformsRefs {
53
- downloadPlatformByRef (pm , platformRef )
54
- }
55
- }
56
-
57
- func downloadPlatformByRef (pm * packagemanager.PackageManager , platformsRef * packagemanager.PlatformReference ) {
58
- platform , tools , err := pm .FindPlatformReleaseDependencies (platformsRef )
59
- if err != nil {
60
- formatter .PrintError (err , "Could not determine platform dependencies" )
61
- os .Exit (cli .ErrBadCall )
62
- }
63
- downloadPlatform (pm , platform )
64
- for _ , tool := range tools {
65
- downloadTool (pm , tool )
66
- }
67
- }
68
-
69
- func downloadPlatform (pm * packagemanager.PackageManager , platformRelease * cores.PlatformRelease ) {
70
- // Download platform
71
- resp , err := pm .DownloadPlatformRelease (platformRelease )
72
- download (resp , err , platformRelease .String ())
73
- }
74
-
75
- func downloadTool (pm * packagemanager.PackageManager , tool * cores.ToolRelease ) {
76
- // Check if tool has a flavor available for the current OS
77
- if tool .GetCompatibleFlavour () == nil {
78
- formatter .PrintErrorMessage ("The tool " + tool .String () + " is not available for the current OS" )
79
- os .Exit (cli .ErrGeneric )
80
- }
81
-
82
- DownloadToolRelease (pm , tool )
83
- }
84
-
85
- // DownloadToolRelease downloads a ToolRelease
86
- func DownloadToolRelease (pm * packagemanager.PackageManager , toolRelease * cores.ToolRelease ) {
87
- resp , err := pm .DownloadToolRelease (toolRelease )
88
- download (resp , err , toolRelease .String ())
89
- }
90
-
91
- func download (d * downloader.Downloader , err error , label string ) {
92
- if err != nil {
93
- formatter .PrintError (err , "Error downloading " + label )
94
- os .Exit (cli .ErrNetwork )
95
- }
96
- if d == nil {
97
- formatter .Print (label + " already downloaded" )
98
- return
99
- }
100
- formatter .Print ("Downloading " + label + "..." )
101
- formatter .DownloadProgressBar (d , label )
102
- if d .Error () != nil {
103
- formatter .PrintError (d .Error (), "Error downloading " + label )
104
- os .Exit (cli .ErrNetwork )
50
+ core .PlatformDownload (context .Background (), & rpc.PlatformDownloadReq {
51
+ Instance : instance ,
52
+ PlatformPackage : platformRef .Package ,
53
+ Architecture : platformRef .PlatformArchitecture ,
54
+ Version : platformRef .PlatformVersion .String (),
55
+ })
105
56
}
106
57
}
0 commit comments