@@ -26,12 +26,15 @@ import (
26
26
"github.com/arduino/arduino-cli/cli/instance"
27
27
"github.com/arduino/arduino-cli/cli/output"
28
28
"github.com/arduino/arduino-cli/commands/core"
29
- "github.com/arduino/arduino-cli/configuration"
30
29
rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1"
31
30
"github.com/sirupsen/logrus"
32
31
"github.com/spf13/cobra"
33
32
)
34
33
34
+ var (
35
+ postInstallFlags arguments.PostInstallFlags
36
+ )
37
+
35
38
func initInstallCommand () * cobra.Command {
36
39
installCommand := & cobra.Command {
37
40
Use : fmt .Sprintf ("install %s:%s[@%s]..." , tr ("PACKAGER" ), tr ("ARCH" ), tr ("VERSION" )),
@@ -42,50 +45,18 @@ func initInstallCommand() *cobra.Command {
42
45
" # " + tr ("download a specific version (in this case 1.6.9)." ) + "\n " +
43
46
" " + os .Args [0 ] + " core install arduino:samd@1.6.9" ,
44
47
Args : cobra .MinimumNArgs (1 ),
45
- Run : runInstallCommand ,
48
+ PreRun : func (cmd * cobra.Command , args []string ) {
49
+ arguments .CheckFlagsConflicts (cmd , "run-post-install" , "skip-post-install" )
50
+ },
51
+ Run : runInstallCommand ,
46
52
ValidArgsFunction : func (cmd * cobra.Command , args []string , toComplete string ) ([]string , cobra.ShellCompDirective ) {
47
53
return arguments .GetInstallableCores (), cobra .ShellCompDirectiveDefault
48
54
},
49
55
}
50
- AddPostInstallFlagsToCommand (installCommand )
56
+ postInstallFlags . AddToCommand (installCommand )
51
57
return installCommand
52
58
}
53
59
54
- var postInstallFlags struct {
55
- runPostInstall bool
56
- skipPostInstall bool
57
- }
58
-
59
- // AddPostInstallFlagsToCommand adds flags that can be used to force running or skipping
60
- // of post installation scripts
61
- func AddPostInstallFlagsToCommand (cmd * cobra.Command ) {
62
- cmd .Flags ().BoolVar (& postInstallFlags .runPostInstall , "run-post-install" , false , tr ("Force run of post-install scripts (if the CLI is not running interactively)." ))
63
- cmd .Flags ().BoolVar (& postInstallFlags .skipPostInstall , "skip-post-install" , false , tr ("Force skip of post-install scripts (if the CLI is running interactively)." ))
64
- }
65
-
66
- // DetectSkipPostInstallValue returns true if a post install script must be run
67
- func DetectSkipPostInstallValue () bool {
68
- if postInstallFlags .runPostInstall && postInstallFlags .skipPostInstall {
69
- feedback .Errorf (tr ("The flags --run-post-install and --skip-post-install can't be both set at the same time." ))
70
- os .Exit (errorcodes .ErrBadArgument )
71
- }
72
- if postInstallFlags .runPostInstall {
73
- logrus .Info ("Will run post-install by user request" )
74
- return false
75
- }
76
- if postInstallFlags .skipPostInstall {
77
- logrus .Info ("Will skip post-install by user request" )
78
- return true
79
- }
80
-
81
- if ! configuration .IsInteractive {
82
- logrus .Info ("Not running from console, will skip post-install by default" )
83
- return true
84
- }
85
- logrus .Info ("Running from console, will run post-install by default" )
86
- return false
87
- }
88
-
89
60
func runInstallCommand (cmd * cobra.Command , args []string ) {
90
61
inst := instance .CreateAndInit ()
91
62
logrus .Info ("Executing `arduino core install`" )
@@ -102,7 +73,7 @@ func runInstallCommand(cmd *cobra.Command, args []string) {
102
73
PlatformPackage : platformRef .PackageName ,
103
74
Architecture : platformRef .Architecture ,
104
75
Version : platformRef .Version ,
105
- SkipPostInstall : DetectSkipPostInstallValue (),
76
+ SkipPostInstall : postInstallFlags . DetectSkipPostInstallValue (),
106
77
}
107
78
_ , err := core .PlatformInstall (context .Background (), platformInstallRequest , output .ProgressBar (), output .TaskProgress ())
108
79
if err != nil {
0 commit comments