@@ -18,15 +18,12 @@ package arguments
1818import (
1919 "fmt"
2020 "net/url"
21- "os"
2221 "time"
2322
2423 "github.com/arduino/arduino-cli/arduino/discovery"
2524 "github.com/arduino/arduino-cli/arduino/sketch"
26- "github.com/arduino/arduino-cli/cli/errorcodes"
2725 "github.com/arduino/arduino-cli/cli/feedback"
2826 "github.com/arduino/arduino-cli/commands"
29- "github.com/arduino/arduino-cli/configuration"
3027 rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1"
3128 "github.com/pkg/errors"
3229 "github.com/sirupsen/logrus"
@@ -42,26 +39,6 @@ type Port struct {
4239 timeout time.Duration
4340}
4441
45- // Fqbn contains the Fqbn arguments result.
46- // This is useful so all flags used by commands that need
47- // this information are consistent with each other.
48- type Fqbn struct {
49- fqbn string
50- }
51-
52- // Programmer contains the arguments result.
53- // This is useful so all flags used by commands that need
54- // this information are consistent with each other.
55- type Programmer struct {
56- programmer string
57- }
58-
59- // PostInstallFlags contains flags used by the
60- type PostInstallFlags struct {
61- runPostInstall bool // force the execution of installation scripts
62- skipPostInstall bool //skip the execution of installation scripts
63- }
64-
6542// AddToCommand adds the flags used to set port and protocol to the specified Command
6643func (p * Port ) AddToCommand (cmd * cobra.Command ) {
6744 cmd .Flags ().StringVarP (& p .address , "port" , "p" , "" , tr ("Upload port address, e.g.: COM3 or /dev/ttyACM2" ))
@@ -75,54 +52,6 @@ func (p *Port) AddToCommand(cmd *cobra.Command) {
7552 cmd .Flags ().DurationVar (& p .timeout , "discovery-timeout" , 5 * time .Second , tr ("Max time to wait for port discovery, e.g.: 30s, 1m" ))
7653}
7754
78- // AddToCommand adds the flags used to set fqbn to the specified Command
79- func (f * Fqbn ) AddToCommand (cmd * cobra.Command ) {
80- cmd .Flags ().StringVarP (& f .fqbn , "fqbn" , "b" , "" , tr ("Fully Qualified Board Name, e.g.: arduino:avr:uno" ))
81- cmd .RegisterFlagCompletionFunc ("fqbn" , func (cmd * cobra.Command , args []string , toComplete string ) ([]string , cobra.ShellCompDirective ) {
82- return GetInstalledBoards (), cobra .ShellCompDirectiveDefault
83- })
84- }
85-
86- // AddToCommand adds the flags used to set the programmer to the specified Command
87- func (p * Programmer ) AddToCommand (cmd * cobra.Command ) {
88- cmd .Flags ().StringVarP (& p .programmer , "programmer" , "P" , "" , tr ("Use the specified programmer to upload." ))
89- cmd .RegisterFlagCompletionFunc ("programmer" , func (cmd * cobra.Command , args []string , toComplete string ) ([]string , cobra.ShellCompDirective ) {
90- return GetInstalledProgrammers (), cobra .ShellCompDirectiveDefault
91- })
92- }
93-
94- // AddToCommand adds flags that can be used to force running or skipping
95- // of post installation scripts
96- func (p * PostInstallFlags ) AddToCommand (cmd * cobra.Command ) {
97- cmd .Flags ().BoolVar (& p .runPostInstall , "run-post-install" , false , tr ("Force run of post-install scripts (if the CLI is not running interactively)." ))
98- cmd .Flags ().BoolVar (& p .skipPostInstall , "skip-post-install" , false , tr ("Force skip of post-install scripts (if the CLI is running interactively)." ))
99- }
100-
101- // GetRunPostInstall returns the runPostInstall flag
102- func (p * PostInstallFlags ) GetRunPostInstall () bool {
103- return p .runPostInstall
104- }
105-
106- // GetSkipPostInstall returns the skipPostInstall
107- func (p * PostInstallFlags ) GetSkipPostInstall () bool {
108- return p .skipPostInstall
109- }
110-
111- // GetFQBN returns the fqbn
112- func (f * Fqbn ) GetFQBN () string {
113- return f .fqbn
114- }
115-
116- // SetFQBN sets the fqbn
117- func (f * Fqbn ) SetFQBN (fqbn string ) {
118- f .fqbn = fqbn
119- }
120-
121- // GetProgrammer returns the programmer
122- func (p * Programmer ) GetProgrammer () string {
123- return p .programmer
124- }
125-
12655// GetPortAddressAndProtocol returns only the port address and the port protocol
12756// without any other port metadata obtained from the discoveries. This method allows
12857// to bypass the discoveries unless the protocol is not specified: in this
@@ -220,32 +149,3 @@ func (p *Port) GetPort(instance *rpc.Instance, sk *sketch.Sketch) (*discovery.Po
220149func (p * Port ) GetSearchTimeout () time.Duration {
221150 return p .timeout
222151}
223-
224- // CheckFlagsConflicts is a helper function useful to report errors when 2 conflicting flags are used
225- func CheckFlagsConflicts (command * cobra.Command , firstFlagName , secondFlagName string ) {
226- flag1 , _ := command .Flags ().GetString (firstFlagName )
227- flag2 , _ := command .Flags ().GetString (secondFlagName )
228- if flag1 != "" && flag2 != "" {
229- feedback .Errorf (tr ("Can't use both --%s and --%s flags at the same time." , firstFlagName , secondFlagName ))
230- os .Exit (errorcodes .ErrBadArgument )
231- }
232- }
233-
234- // DetectSkipPostInstallValue returns true if a post install script must be run
235- func (p * PostInstallFlags ) DetectSkipPostInstallValue () bool {
236- if p .GetRunPostInstall () {
237- logrus .Info ("Will run post-install by user request" )
238- return false
239- }
240- if p .GetSkipPostInstall () {
241- logrus .Info ("Will skip post-install by user request" )
242- return true
243- }
244-
245- if ! configuration .IsInteractive {
246- logrus .Info ("Not running from console, will skip post-install by default" )
247- return true
248- }
249- logrus .Info ("Running from console, will run post-install by default" )
250- return false
251- }
0 commit comments