Skip to content

Commit 64f7107

Browse files
committed
[breaking] replace board attach <port|fqbn> <sketch-path> with board attach -b <fqbn> | -p <port> <sketh-path>
1 parent 66dbc61 commit 64f7107

File tree

4 files changed

+37
-24
lines changed

4 files changed

+37
-24
lines changed

cli/arguments/port.go

+5
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,11 @@ func (p *Port) GetPort(instance *rpc.Instance, sk *sketch.Sketch) (*discovery.Po
216216
}
217217
}
218218

219+
// GetSearchTimeout returns the timeout
220+
func (p *Port) GetSearchTimeout() time.Duration {
221+
return p.timeout
222+
}
223+
219224
// CheckFlagsConflicts is a helper function useful to report errors when 2 conflicting flags are used
220225
func CheckFlagsConflicts(command *cobra.Command, firstFlagName, secondFlagName string) {
221226
flag1, _ := command.Flags().GetString(firstFlagName)

cli/board/attach.go

+24-12
Original file line numberDiff line numberDiff line change
@@ -31,21 +31,24 @@ import (
3131
"github.com/spf13/cobra"
3232
)
3333

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+
)
3537

3638
func initAttachCommand() *cobra.Command {
3739
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")),
3941
Short: tr("Attaches a sketch to a board."),
4042
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),
4547
Run: runAttachCommand,
4648
}
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+
4952
return attachCommand
5053
}
5154

@@ -55,16 +58,25 @@ func runAttachCommand(cmd *cobra.Command, args []string) {
5558
logrus.Info("Executing `arduino-cli board attach`")
5659

5760
path := ""
58-
if len(args) > 1 {
59-
path = args[1]
61+
if len(args) > 0 {
62+
path = args[0]
6063
}
6164
sketchPath := arguments.InitSketchPath(path)
6265

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.GetFQBN() != "" {
71+
boardURI = fqbn.GetFQBN()
72+
} else if discoveryPort != nil {
73+
boardURI = discoveryPort.Address
74+
}
6375
if _, err := board.Attach(context.Background(), &rpc.BoardAttachRequest{
6476
Instance: instance,
65-
BoardUri: args[0],
77+
BoardUri: boardURI,
6678
SketchPath: sketchPath.String(),
67-
SearchTimeout: searchTimeout,
79+
SearchTimeout: port.GetSearchTimeout().String(),
6880
}, output.TaskProgress()); err != nil {
6981
feedback.Errorf(tr("Attach board error: %v"), err)
7082
os.Exit(errorcodes.ErrGeneric)

i18n/data/en.po

+7-11
Original file line numberDiff line numberDiff line change
@@ -190,12 +190,12 @@ msgstr "Arduino core operations."
190190
msgid "Arguments error: %v"
191191
msgstr "Arguments error: %v"
192192

193-
#: cli/board/attach.go:69
193+
#: cli/board/attach.go:81
194194
msgid "Attach board error: %v"
195195
msgstr "Attach board error: %v"
196196

197-
#: cli/board/attach.go:39
198-
#: cli/board/attach.go:40
197+
#: cli/board/attach.go:41
198+
#: cli/board/attach.go:42
199199
#: cli/board/board.go:35
200200
msgid "Attaches a sketch to a board."
201201
msgstr "Attaches a sketch to a board."
@@ -272,7 +272,7 @@ msgstr "Can't open sketch"
272272
msgid "Can't set multiple values in key %v"
273273
msgstr "Can't set multiple values in key %v"
274274

275-
#: cli/arguments/port.go:224
275+
#: cli/arguments/port.go:229
276276
msgid "Can't use both --%s and --%s flags at the same time."
277277
msgstr "Can't use both --%s and --%s flags at the same time."
278278

@@ -1005,7 +1005,7 @@ msgstr "Executable to debug"
10051005
msgid "Expected compiled sketch in directory %s, but is a file instead"
10061006
msgstr "Expected compiled sketch in directory %s, but is a file instead"
10071007

1008-
#: cli/board/attach.go:38
1008+
#: cli/board/attach.go:40
10091009
#: cli/board/details.go:43
10101010
#: cli/board/list.go:90
10111011
#: cli/board/list.go:128
@@ -2010,10 +2010,6 @@ msgstr "TOUCH: error during reset: %s"
20102010
msgid "The TCP port the daemon will listen to"
20112011
msgstr "The TCP port the daemon will listen to"
20122012

2013-
#: cli/board/attach.go:48
2014-
msgid "The connected devices search timeout, raise it if your board doesn't show up (e.g. to %s)."
2015-
msgstr "The connected devices search timeout, raise it if your board doesn't show up (e.g. to %s)."
2016-
20172013
#: cli/board/list.go:51
20182014
msgid "The connected devices search timeout, raise it if your board doesn't show up e.g.: 10s"
20192015
msgstr "The connected devices search timeout, raise it if your board doesn't show up e.g.: 10s"
@@ -3073,7 +3069,7 @@ msgstr "please use --build-property instead."
30733069
msgid "pluggable discovery already added: %s"
30743070
msgstr "pluggable discovery already added: %s"
30753071

3076-
#: cli/board/attach.go:38
3072+
#: cli/board/attach.go:40
30773073
msgid "port"
30783074
msgstr "port"
30793075

@@ -3214,7 +3210,7 @@ msgstr "setting DTR to OFF"
32143210
msgid "sketch path is not valid"
32153211
msgstr "sketch path is not valid"
32163212

3217-
#: cli/board/attach.go:38
3213+
#: cli/board/attach.go:40
32183214
#: cli/sketch/archive.go:38
32193215
msgid "sketchPath"
32203216
msgstr "sketchPath"

test/test_board.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -637,7 +637,7 @@ def test_board_attach_without_sketch_json(run_command, data_dir):
637637
# Create a test sketch
638638
assert run_command(["sketch", "new", sketch_path])
639639

640-
assert run_command(["board", "attach", fqbn, sketch_path])
640+
assert run_command(["board", "attach", "-b", fqbn, sketch_path])
641641

642642

643643
def test_board_search_with_outdated_core(run_command):

0 commit comments

Comments
 (0)