@@ -31,21 +31,24 @@ import (
31
31
"github.com/spf13/cobra"
32
32
)
33
33
34
- var searchTimeout string // Expressed in a parsable duration, is the timeout for the list and attach commands.
34
+ var (
35
+ port arguments.Port
36
+ )
35
37
36
38
func initAttachCommand () * cobra.Command {
37
39
attachCommand := & cobra.Command {
38
- Use : fmt .Sprintf ("attach <%s>|<%s> [%s]" , tr ("port" ), tr ("FQBN" ), tr ("sketchPath" )),
40
+ Use : fmt .Sprintf ("attach -p <%s>|-b <%s> [%s]" , tr ("port" ), tr ("FQBN" ), tr ("sketchPath" )),
39
41
Short : tr ("Attaches a sketch to a board." ),
40
42
Long : tr ("Attaches a sketch to a board." ),
41
- Example : " " + os .Args [0 ] + " board attach serial:// /dev/ttyACM0\n " +
42
- " " + os .Args [0 ] + " board attach serial:// /dev/ttyACM0 HelloWorld\n " +
43
- " " + os .Args [0 ] + " board attach arduino:samd:mkr1000" ,
44
- Args : cobra .RangeArgs ( 1 , 2 ),
43
+ Example : " " + os .Args [0 ] + " board attach -p /dev/ttyACM0\n " +
44
+ " " + os .Args [0 ] + " board attach -p /dev/ttyACM0 HelloWorld\n " +
45
+ " " + os .Args [0 ] + " board attach -b arduino:samd:mkr1000" ,
46
+ Args : cobra .MaximumNArgs ( 1 ),
45
47
Run : runAttachCommand ,
46
48
}
47
- attachCommand .Flags ().StringVar (& searchTimeout , "timeout" , "5s" ,
48
- tr ("The connected devices search timeout, raise it if your board doesn't show up (e.g. to %s)." , "10s" ))
49
+ fqbn .AddToCommand (attachCommand )
50
+ port .AddToCommand (attachCommand )
51
+
49
52
return attachCommand
50
53
}
51
54
@@ -55,16 +58,25 @@ func runAttachCommand(cmd *cobra.Command, args []string) {
55
58
logrus .Info ("Executing `arduino-cli board attach`" )
56
59
57
60
path := ""
58
- if len (args ) > 1 {
59
- path = args [1 ]
61
+ if len (args ) > 0 {
62
+ path = args [0 ]
60
63
}
61
64
sketchPath := arguments .InitSketchPath (path )
62
65
66
+ // ugly hack to allow user to specify fqbn and port as flags (consistency)
67
+ // a more meaningful fix would be to fix board.Attach
68
+ var boardURI string
69
+ discoveryPort , _ := port .GetPort (instance , nil )
70
+ if fqbn .String () != "" {
71
+ boardURI = fqbn .String ()
72
+ } else if discoveryPort != nil {
73
+ boardURI = discoveryPort .Address
74
+ }
63
75
if _ , err := board .Attach (context .Background (), & rpc.BoardAttachRequest {
64
76
Instance : instance ,
65
- BoardUri : args [ 0 ] ,
77
+ BoardUri : boardURI ,
66
78
SketchPath : sketchPath .String (),
67
- SearchTimeout : searchTimeout ,
79
+ SearchTimeout : port . GetSearchTimeout (). String () ,
68
80
}, output .TaskProgress ()); err != nil {
69
81
feedback .Errorf (tr ("Attach board error: %v" ), err )
70
82
os .Exit (errorcodes .ErrGeneric )
0 commit comments