@@ -26,18 +26,37 @@ import (
2626)
2727
2828// PlatformInstall FIXMEDOC
29- func PlatformInstall (ctx context.Context , req * rpc.PlatformInstallRequest ,
30- downloadCB rpc.DownloadProgressCB , taskCB rpc.TaskProgressCB ) (* rpc.PlatformInstallResponse , error ) {
29+ func PlatformInstall (
30+ ctx context.Context ,
31+ req * rpc.PlatformInstallRequest ,
32+ downloadCB rpc.DownloadProgressCB ,
33+ taskCB rpc.TaskProgressCB ,
34+ ) (* rpc.PlatformInstallResponse , error ) {
35+ if err := platformInstall (ctx , req , downloadCB , taskCB ); err != nil {
36+ return nil , err
37+ }
38+ if err := commands .Init (& rpc.InitRequest {Instance : req .Instance }, nil ); err != nil {
39+ return nil , err
40+ }
41+ return & rpc.PlatformInstallResponse {}, nil
42+ }
3143
44+ // platformInstall is the implementation of platform install
45+ func platformInstall (
46+ ctx context.Context ,
47+ req * rpc.PlatformInstallRequest ,
48+ downloadCB rpc.DownloadProgressCB ,
49+ taskCB rpc.TaskProgressCB ,
50+ ) error {
3251 pme , release := commands .GetPackageManagerExplorer (req )
3352 if pme == nil {
34- return nil , & arduino.InvalidInstanceError {}
53+ return & arduino.InvalidInstanceError {}
3554 }
3655 defer release ()
3756
3857 version , err := commands .ParseVersion (req )
3958 if err != nil {
40- return nil , & arduino.InvalidVersionError {Cause : err }
59+ return & arduino.InvalidVersionError {Cause : err }
4160 }
4261
4362 ref := & packagemanager.PlatformReference {
@@ -47,30 +66,26 @@ func PlatformInstall(ctx context.Context, req *rpc.PlatformInstallRequest,
4766 }
4867 platformRelease , tools , err := pme .FindPlatformReleaseDependencies (ref )
4968 if err != nil {
50- return nil , & arduino.PlatformNotFoundError {Platform : ref .String (), Cause : err }
69+ return & arduino.PlatformNotFoundError {Platform : ref .String (), Cause : err }
5170 }
5271
5372 // Prerequisite checks before install
5473 if platformRelease .IsInstalled () {
5574 taskCB (& rpc.TaskProgress {Name : tr ("Platform %s already installed" , platformRelease ), Completed : true })
56- return & rpc. PlatformInstallResponse {}, nil
75+ return nil
5776 }
5877
5978 if req .GetNoOverwrite () {
6079 if installed := pme .GetInstalledPlatformRelease (platformRelease .Platform ); installed != nil {
61- return nil , fmt .Errorf ("%s: %s" ,
80+ return fmt .Errorf ("%s: %s" ,
6281 tr ("Platform %s already installed" , installed ),
6382 tr ("could not overwrite" ))
6483 }
6584 }
6685
6786 if err := pme .DownloadAndInstallPlatformAndTools (platformRelease , tools , downloadCB , taskCB , req .GetSkipPostInstall ()); err != nil {
68- return nil , err
69- }
70-
71- if err := commands .Init (& rpc.InitRequest {Instance : req .Instance }, nil ); err != nil {
72- return nil , err
87+ return err
7388 }
7489
75- return & rpc. PlatformInstallResponse {}, nil
90+ return nil
7691}
0 commit comments