@@ -26,12 +26,15 @@ import (
2626 "github.com/arduino/arduino-cli/cli/instance"
2727 "github.com/arduino/arduino-cli/cli/output"
2828 "github.com/arduino/arduino-cli/commands/core"
29- "github.com/arduino/arduino-cli/configuration"
3029 rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1"
3130 "github.com/sirupsen/logrus"
3231 "github.com/spf13/cobra"
3332)
3433
34+ var (
35+ postInstallFlags arguments.PostInstallFlags
36+ )
37+
3538func initInstallCommand () * cobra.Command {
3639 installCommand := & cobra.Command {
3740 Use : fmt .Sprintf ("install %s:%s[@%s]..." , tr ("PACKAGER" ), tr ("ARCH" ), tr ("VERSION" )),
@@ -42,50 +45,18 @@ func initInstallCommand() *cobra.Command {
4245 " # " + tr ("download a specific version (in this case 1.6.9)." ) + "\n " +
4346 " " + os .Args [0 ] + " core install arduino:samd@1.6.9" ,
4447 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 ,
4652 ValidArgsFunction : func (cmd * cobra.Command , args []string , toComplete string ) ([]string , cobra.ShellCompDirective ) {
4753 return arguments .GetInstallableCores (), cobra .ShellCompDirectiveDefault
4854 },
4955 }
50- AddPostInstallFlagsToCommand (installCommand )
56+ postInstallFlags . AddToCommand (installCommand )
5157 return installCommand
5258}
5359
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-
8960func runInstallCommand (cmd * cobra.Command , args []string ) {
9061 inst := instance .CreateAndInit ()
9162 logrus .Info ("Executing `arduino core install`" )
@@ -102,7 +73,7 @@ func runInstallCommand(cmd *cobra.Command, args []string) {
10273 PlatformPackage : platformRef .PackageName ,
10374 Architecture : platformRef .Architecture ,
10475 Version : platformRef .Version ,
105- SkipPostInstall : DetectSkipPostInstallValue (),
76+ SkipPostInstall : postInstallFlags . DetectSkipPostInstallValue (),
10677 }
10778 _ , err := core .PlatformInstall (context .Background (), platformInstallRequest , output .ProgressBar (), output .TaskProgress ())
10879 if err != nil {
0 commit comments