Skip to content

Commit 151a1cd

Browse files
committed
Moved some flags in the command creation
This will turn out useful in the following commits
1 parent 55025fe commit 151a1cd

File tree

2 files changed

+16
-10
lines changed

2 files changed

+16
-10
lines changed

cli/core/install.go

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,9 @@ import (
3131
"github.com/spf13/cobra"
3232
)
3333

34-
var (
35-
postInstallFlags arguments.PostInstallFlags
36-
noOverwrite bool
37-
)
38-
3934
func initInstallCommand() *cobra.Command {
35+
var noOverwrite bool
36+
var postInstallFlags arguments.PostInstallFlags
4037
installCommand := &cobra.Command{
4138
Use: fmt.Sprintf("install %s:%s[@%s]...", tr("PACKAGER"), tr("ARCH"), tr("VERSION")),
4239
Short: tr("Installs one or more cores and corresponding tool dependencies."),
@@ -49,7 +46,9 @@ func initInstallCommand() *cobra.Command {
4946
PreRun: func(cmd *cobra.Command, args []string) {
5047
arguments.CheckFlagsConflicts(cmd, "run-post-install", "skip-post-install")
5148
},
52-
Run: runInstallCommand,
49+
Run: func(cmd *cobra.Command, args []string) {
50+
runInstallCommand(args, postInstallFlags, noOverwrite)
51+
},
5352
ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
5453
return arguments.GetInstallableCores(), cobra.ShellCompDirectiveDefault
5554
},
@@ -59,7 +58,7 @@ func initInstallCommand() *cobra.Command {
5958
return installCommand
6059
}
6160

62-
func runInstallCommand(cmd *cobra.Command, args []string) {
61+
func runInstallCommand(args []string, postInstallFlags arguments.PostInstallFlags, noOverwrite bool) {
6362
inst := instance.CreateAndInit()
6463
logrus.Info("Executing `arduino-cli core install`")
6564

cli/core/upgrade.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import (
3434
)
3535

3636
func initUpgradeCommand() *cobra.Command {
37+
var postInstallFlags arguments.PostInstallFlags
3738
upgradeCommand := &cobra.Command{
3839
Use: fmt.Sprintf("upgrade [%s:%s] ...", tr("PACKAGER"), tr("ARCH")),
3940
Short: tr("Upgrades one or all installed platforms to the latest version."),
@@ -43,16 +44,22 @@ func initUpgradeCommand() *cobra.Command {
4344
" " + os.Args[0] + " core upgrade\n\n" +
4445
" # " + tr("upgrade arduino:samd to the latest version") + "\n" +
4546
" " + os.Args[0] + " core upgrade arduino:samd",
46-
Run: runUpgradeCommand,
47+
Run: func(cmd *cobra.Command, args []string) {
48+
runUpgradeCommand(args, postInstallFlags.DetectSkipPostInstallValue())
49+
},
4750
}
4851
postInstallFlags.AddToCommand(upgradeCommand)
4952
return upgradeCommand
5053
}
5154

52-
func runUpgradeCommand(cmd *cobra.Command, args []string) {
55+
func runUpgradeCommand(args []string, skipPostInstall bool) {
5356
inst := instance.CreateAndInit()
5457
logrus.Info("Executing `arduino-cli core upgrade`")
58+
Upgrade(inst, args, skipPostInstall)
59+
}
5560

61+
// Upgrade upgrades one or all installed platforms to the latest version.
62+
func Upgrade(inst *rpc.Instance, args []string, skipPostInstall bool) {
5663
// if no platform was passed, upgrade allthethings
5764
if len(args) == 0 {
5865
targets, err := core.GetPlatforms(&rpc.PlatformListRequest{
@@ -93,7 +100,7 @@ func runUpgradeCommand(cmd *cobra.Command, args []string) {
93100
Instance: inst,
94101
PlatformPackage: platformRef.PackageName,
95102
Architecture: platformRef.Architecture,
96-
SkipPostInstall: postInstallFlags.DetectSkipPostInstallValue(),
103+
SkipPostInstall: skipPostInstall,
97104
}
98105

99106
if _, err := core.PlatformUpgrade(context.Background(), r, output.ProgressBar(), output.TaskProgress()); err != nil {

0 commit comments

Comments
 (0)