Skip to content

Commit 68c20cd

Browse files
committed
Add --run-post-install and --skip-post-install flags to upgrade command
1 parent 47aafe3 commit 68c20cd

File tree

13 files changed

+309
-246
lines changed

13 files changed

+309
-246
lines changed

cli/upgrade/upgrade.go

+32-1
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,39 @@ import (
2424
"github.com/arduino/arduino-cli/cli/instance"
2525
"github.com/arduino/arduino-cli/cli/output"
2626
"github.com/arduino/arduino-cli/commands"
27+
"github.com/arduino/arduino-cli/configuration"
2728
rpc "github.com/arduino/arduino-cli/rpc/commands"
2829
"github.com/sirupsen/logrus"
2930
"github.com/spf13/cobra"
3031
)
3132

33+
var postInstallFlags struct {
34+
runPostInstall bool
35+
skipPostInstall bool
36+
}
37+
38+
func detectSkipPostInstallValue() bool {
39+
if postInstallFlags.runPostInstall && postInstallFlags.skipPostInstall {
40+
feedback.Errorf("The flags --run-post-install and --skip-post-install can't be both set at the same time.")
41+
os.Exit(errorcodes.ErrBadArgument)
42+
}
43+
if postInstallFlags.runPostInstall {
44+
logrus.Info("Will run post-install by user request")
45+
return false
46+
}
47+
if postInstallFlags.skipPostInstall {
48+
logrus.Info("Will skip post-install by user request")
49+
return true
50+
}
51+
52+
if !configuration.IsInteractive {
53+
logrus.Info("Not running from console, will skip post-install by default")
54+
return true
55+
}
56+
logrus.Info("Running from console, will run post-install by default")
57+
return false
58+
}
59+
3260
// NewCommand creates a new `upgrade` command
3361
func NewCommand() *cobra.Command {
3462
upgradeCommand := &cobra.Command{
@@ -40,6 +68,8 @@ func NewCommand() *cobra.Command {
4068
Run: runUpgradeCommand,
4169
}
4270

71+
upgradeCommand.Flags().BoolVar(&postInstallFlags.runPostInstall, "run-post-install", false, "Force run of post-install scripts (if the CLI is not running interactively).")
72+
upgradeCommand.Flags().BoolVar(&postInstallFlags.skipPostInstall, "skip-post-install", false, "Force skip of post-install scripts (if the CLI is running interactively).")
4373
return upgradeCommand
4474
}
4575

@@ -53,7 +83,8 @@ func runUpgradeCommand(cmd *cobra.Command, args []string) {
5383
logrus.Info("Executing `arduino upgrade`")
5484

5585
err = commands.Upgrade(context.Background(), &rpc.UpgradeReq{
56-
Instance: inst,
86+
Instance: inst,
87+
SkipPostInstall: detectSkipPostInstallValue(),
5788
}, output.NewDownloadProgressBarCB(), output.TaskProgress())
5889

5990
if err != nil {

commands/instances.go

+18-1
Original file line numberDiff line numberDiff line change
@@ -515,6 +515,7 @@ func Upgrade(ctx context.Context, req *rpc.UpgradeReq, downloadCB DownloadProgre
515515
toolsToInstall := []*cores.ToolRelease{}
516516
for _, tool := range tools {
517517
if tool.IsInstalled() {
518+
logrus.WithField("tool", tool).Warn("Tool already installed")
518519
taskCB(&rpc.TaskProgress{Name: "Tool " + tool.String() + " already installed", Completed: true})
519520
} else {
520521
toolsToInstall = append(toolsToInstall, tool)
@@ -536,7 +537,8 @@ func Upgrade(ctx context.Context, req *rpc.UpgradeReq, downloadCB DownloadProgre
536537
return err
537538
}
538539

539-
taskCB(&rpc.TaskProgress{Name: "Installing " + latest.String()})
540+
logrus.Info("Updating platform " + installed.String())
541+
taskCB(&rpc.TaskProgress{Name: "Updating " + latest.String()})
540542

541543
// Installs tools
542544
for _, tool := range toolsToInstall {
@@ -549,6 +551,7 @@ func Upgrade(ctx context.Context, req *rpc.UpgradeReq, downloadCB DownloadProgre
549551
// Installs platform
550552
err = pm.InstallPlatform(latest)
551553
if err != nil {
554+
logrus.WithError(err).Error("Cannot install platform")
552555
taskCB(&rpc.TaskProgress{Message: "Error installing " + latest.String()})
553556
return err
554557
}
@@ -558,13 +561,27 @@ func Upgrade(ctx context.Context, req *rpc.UpgradeReq, downloadCB DownloadProgre
558561

559562
// In case uninstall fails tries to rollback
560563
if err != nil {
564+
logrus.WithError(err).Error("Error updating platform.")
561565
taskCB(&rpc.TaskProgress{Message: "Error upgrading platform: " + err.Error()})
562566

563567
// Rollback
564568
if err := pm.UninstallPlatform(latest); err != nil {
569+
logrus.WithError(err).Error("Error rolling-back changes.")
565570
taskCB(&rpc.TaskProgress{Message: "Error rolling-back changes: " + err.Error()})
566571
}
567572
}
573+
574+
// Perform post install
575+
if !req.SkipPostInstall {
576+
logrus.Info("Running post_install script")
577+
taskCB(&rpc.TaskProgress{Message: "Configuring platform"})
578+
if err := pm.RunPostInstallScript(latest); err != nil {
579+
taskCB(&rpc.TaskProgress{Message: fmt.Sprintf("WARNING: cannot run post install: %s", err)})
580+
}
581+
} else {
582+
logrus.Info("Skipping platform configuration (post_install run).")
583+
taskCB(&rpc.TaskProgress{Message: "Skipping platform configuration"})
584+
}
568585
}
569586
}
570587
}

rpc/commands/board.pb.go

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)