Skip to content

Commit 9ef725a

Browse files
committed
Added --no-overwrite flag in core install
1 parent 88cad2b commit 9ef725a

File tree

4 files changed

+125
-97
lines changed

4 files changed

+125
-97
lines changed

cli/core/install.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import (
3333

3434
var (
3535
postInstallFlags arguments.PostInstallFlags
36+
noOverwrite bool
3637
)
3738

3839
func initInstallCommand() *cobra.Command {
@@ -54,6 +55,7 @@ func initInstallCommand() *cobra.Command {
5455
},
5556
}
5657
postInstallFlags.AddToCommand(installCommand)
58+
installCommand.Flags().BoolVar(&noOverwrite, "no-overwrite", false, tr("Do not overwrite existing platforms (during upgrade or downgrade)."))
5759
return installCommand
5860
}
5961

@@ -74,6 +76,7 @@ func runInstallCommand(cmd *cobra.Command, args []string) {
7476
Architecture: platformRef.Architecture,
7577
Version: platformRef.Version,
7678
SkipPostInstall: postInstallFlags.DetectSkipPostInstallValue(),
79+
NoOverwrite: noOverwrite,
7780
}
7881
_, err := core.PlatformInstall(context.Background(), platformInstallRequest, output.ProgressBar(), output.TaskProgress())
7982
if err != nil {

commands/core/install.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ package core
1717

1818
import (
1919
"context"
20+
"fmt"
2021

2122
"github.com/arduino/arduino-cli/arduino"
2223
"github.com/arduino/arduino-cli/arduino/cores"
@@ -55,6 +56,14 @@ func PlatformInstall(ctx context.Context, req *rpc.PlatformInstallRequest,
5556
return &rpc.PlatformInstallResponse{}, nil
5657
}
5758

59+
if req.GetNoOverwrite() {
60+
if installed := pm.GetInstalledPlatformRelease(platformRelease.Platform); installed != nil {
61+
return nil, fmt.Errorf("%s: %s",
62+
tr("Platform %s already installed", installed),
63+
tr("could not overwrite"))
64+
}
65+
}
66+
5867
if err := installPlatform(pm, platformRelease, tools, downloadCB, taskCB, req.GetSkipPostInstall()); err != nil {
5968
return nil, err
6069
}

0 commit comments

Comments
 (0)