Skip to content

Commit e0f0051

Browse files
Add pre-uninstall flags to CLI arguments
1 parent d82dd0a commit e0f0051

File tree

4 files changed

+45
-12
lines changed

4 files changed

+45
-12
lines changed

internal/cli/arguments/post_install.go renamed to internal/cli/arguments/pre_post_script.go

+41-8
Original file line numberDiff line numberDiff line change
@@ -21,33 +21,47 @@ import (
2121
"github.com/spf13/cobra"
2222
)
2323

24-
// PostInstallFlags contains flags data used by the core install and the upgrade command
24+
// PrePostScriptsFlags contains flags data used by the core install and the upgrade command
2525
// This is useful so all flags used by commands that need
2626
// this information are consistent with each other.
27-
type PostInstallFlags struct {
28-
runPostInstall bool // force the execution of installation scripts
29-
skipPostInstall bool // skip the execution of installation scripts
27+
type PrePostScriptsFlags struct {
28+
runPostInstall bool // force the execution of installation scripts
29+
skipPostInstall bool // skip the execution of installation scripts
30+
runPreUninstall bool // force the execution of pre uninstall scripts
31+
skipPreUninstall bool // skip the execution of pre uninstall scripts
3032
}
3133

3234
// AddToCommand adds flags that can be used to force running or skipping
3335
// of post installation scripts
34-
func (p *PostInstallFlags) AddToCommand(cmd *cobra.Command) {
36+
func (p *PrePostScriptsFlags) AddToCommand(cmd *cobra.Command) {
3537
cmd.Flags().BoolVar(&p.runPostInstall, "run-post-install", false, tr("Force run of post-install scripts (if the CLI is not running interactively)."))
3638
cmd.Flags().BoolVar(&p.skipPostInstall, "skip-post-install", false, tr("Force skip of post-install scripts (if the CLI is running interactively)."))
39+
cmd.Flags().BoolVar(&p.runPreUninstall, "run-pre-uninstall", false, tr("Force run of pre-uninstall scripts (if the CLI is not running interactively)."))
40+
cmd.Flags().BoolVar(&p.skipPreUninstall, "skip-pre-uninstall", false, tr("Force skip of pre-uninstall scripts (if the CLI is running interactively)."))
3741
}
3842

3943
// GetRunPostInstall returns the run-post-install flag value
40-
func (p *PostInstallFlags) GetRunPostInstall() bool {
44+
func (p *PrePostScriptsFlags) GetRunPostInstall() bool {
4145
return p.runPostInstall
4246
}
4347

4448
// GetSkipPostInstall returns the skip-post-install flag value
45-
func (p *PostInstallFlags) GetSkipPostInstall() bool {
49+
func (p *PrePostScriptsFlags) GetSkipPostInstall() bool {
4650
return p.skipPostInstall
4751
}
4852

53+
// GetRunPreUninstall returns the run-post-install flag value
54+
func (p *PrePostScriptsFlags) GetRunPreUninstall() bool {
55+
return p.runPreUninstall
56+
}
57+
58+
// GetSkipPreUninstall returns the skip-post-install flag value
59+
func (p *PrePostScriptsFlags) GetSkipPreUninstall() bool {
60+
return p.skipPreUninstall
61+
}
62+
4963
// DetectSkipPostInstallValue returns true if a post install script must be run
50-
func (p *PostInstallFlags) DetectSkipPostInstallValue() bool {
64+
func (p *PrePostScriptsFlags) DetectSkipPostInstallValue() bool {
5165
if p.GetRunPostInstall() {
5266
logrus.Info("Will run post-install by user request")
5367
return false
@@ -64,3 +78,22 @@ func (p *PostInstallFlags) DetectSkipPostInstallValue() bool {
6478
logrus.Info("Running from console, will run post-install by default")
6579
return false
6680
}
81+
82+
// DetectSkipPreUninstallValue returns true if a post install script must be run
83+
func (p *PrePostScriptsFlags) DetectSkipPreUninstallValue() bool {
84+
if p.GetRunPreUninstall() {
85+
logrus.Info("Will run pre-uninstall by user request")
86+
return false
87+
}
88+
if p.GetSkipPreUninstall() {
89+
logrus.Info("Will skip pre-uninstall by user request")
90+
return true
91+
}
92+
93+
if !configuration.IsInteractive {
94+
logrus.Info("Not running from console, will skip pre-uninstall by default")
95+
return true
96+
}
97+
logrus.Info("Running from console, will run pre-uninstall by default")
98+
return false
99+
}

internal/cli/core/install.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import (
3131

3232
func initInstallCommand() *cobra.Command {
3333
var noOverwrite bool
34-
var postInstallFlags arguments.PostInstallFlags
34+
var postInstallFlags arguments.PrePostScriptsFlags
3535
installCommand := &cobra.Command{
3636
Use: fmt.Sprintf("install %s:%s[@%s]...", tr("PACKAGER"), tr("ARCH"), tr("VERSION")),
3737
Short: tr("Installs one or more cores and corresponding tool dependencies."),
@@ -56,7 +56,7 @@ func initInstallCommand() *cobra.Command {
5656
return installCommand
5757
}
5858

59-
func runInstallCommand(args []string, postInstallFlags arguments.PostInstallFlags, noOverwrite bool) {
59+
func runInstallCommand(args []string, postInstallFlags arguments.PrePostScriptsFlags, noOverwrite bool) {
6060
inst := instance.CreateAndInit()
6161
logrus.Info("Executing `arduino-cli core install`")
6262

internal/cli/core/upgrade.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ import (
3232
)
3333

3434
func initUpgradeCommand() *cobra.Command {
35-
var postInstallFlags arguments.PostInstallFlags
35+
var postInstallFlags arguments.PrePostScriptsFlags
3636
upgradeCommand := &cobra.Command{
3737
Use: fmt.Sprintf("upgrade [%s:%s] ...", tr("PACKAGER"), tr("ARCH")),
3838
Short: tr("Upgrades one or all installed platforms to the latest version."),

internal/cli/upgrade/upgrade.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ var tr = i18n.Tr
3131

3232
// NewCommand creates a new `upgrade` command
3333
func NewCommand() *cobra.Command {
34-
var postInstallFlags arguments.PostInstallFlags
34+
var postInstallFlags arguments.PrePostScriptsFlags
3535
upgradeCommand := &cobra.Command{
3636
Use: "upgrade",
3737
Short: tr("Upgrades installed cores and libraries."),

0 commit comments

Comments
 (0)