Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit f85513c

Browse files
committed
[breaking] replace board attach <port|fqbn> <sketch-path> with board attach -b <fqbn> | -p <port> <sketh-path>
1 parent 633c177 commit f85513c

File tree

3 files changed

+30
-13
lines changed

3 files changed

+30
-13
lines changed

‎cli/arguments/port.go‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,11 @@ func (p *Port) GetPort(instance *rpc.Instance, sk *sketch.Sketch) (*discovery.Po
147147
}
148148
}
149149

150+
// GetSearchTimeout returns the timeout
151+
func (p *Port) GetSearchTimeout() time.Duration {
152+
return p.timeout
153+
}
154+
150155
// GetDiscoveryPort is a helper function useful to get the port and handle possible errors
151156
func (p *Port) GetDiscoveryPort(instance *rpc.Instance, sk *sketch.Sketch) *discovery.Port {
152157
discoveryPort, err := p.GetPort(instance, sk)

‎cli/board/attach.go‎

Lines changed: 24 additions & 12 deletions
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.String() != "" {
71+
boardURI = fqbn.String()
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)

‎test/test_board.py‎

Lines changed: 1 addition & 1 deletion
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)

AltStyle によって変換されたページ (->オリジナル) /