|
16 | 16 | package board
|
17 | 17 |
|
18 | 18 | import (
|
| 19 | + "context" |
19 | 20 | "fmt"
|
20 | 21 | "os"
|
21 | 22 |
|
| 23 | + "github.com/arduino/arduino-cli/commands/sketch" |
22 | 24 | "github.com/arduino/arduino-cli/internal/cli/arguments"
|
23 | 25 | "github.com/arduino/arduino-cli/internal/cli/feedback"
|
| 26 | + rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1" |
24 | 27 | "github.com/spf13/cobra"
|
25 | 28 | )
|
26 | 29 |
|
@@ -51,37 +54,28 @@ func initAttachCommand() *cobra.Command {
|
51 | 54 |
|
52 | 55 | func runAttachCommand(path string, port *arguments.Port, fqbn string) {
|
53 | 56 | sketchPath := arguments.InitSketchPath(path)
|
54 |
| - sk := arguments.NewSketch(sketchPath) |
55 | 57 |
|
56 |
| - var currentPort *boardAttachPortResult |
57 |
| - if currentAddress, currentProtocol := sk.GetDefaultPortAddressAndProtocol(); currentAddress != "" { |
58 |
| - currentPort = &boardAttachPortResult{ |
59 |
| - Address: currentAddress, |
60 |
| - Protocol: currentProtocol, |
61 |
| - } |
62 |
| - } |
63 |
| - current := &boardAttachResult{ |
64 |
| - Port: currentPort, |
65 |
| - Fqbn: sk.GetDefaultFQBN(), |
| 58 | + portAddress, portProtocol, _ := port.GetPortAddressAndProtocol(nil, "", "") |
| 59 | + newDefaults, err := sketch.SetSketchDefaults(context.Background(), &rpc.SetSketchDefaultsRequest{ |
| 60 | + SketchPath: sketchPath.String(), |
| 61 | + DefaultFqbn: fqbn, |
| 62 | + DefaultPortAddress: portAddress, |
| 63 | + DefaultPortProtocol: portProtocol, |
| 64 | + }) |
| 65 | + if err != nil { |
| 66 | + feedback.FatalError(err, feedback.ErrGeneric) |
66 | 67 | }
|
67 |
| - address, protocol, _ := port.GetPortAddressAndProtocol(nil, sk) |
68 |
| - if address != "" { |
69 |
| - if err := sk.SetDefaultPort(address, protocol); err != nil { |
70 |
| - feedback.Fatal(fmt.Sprintf("%s: %s", tr("Error saving sketch metadata"), err), feedback.ErrGeneric) |
71 |
| - } |
72 |
| - current.Port = &boardAttachPortResult{ |
73 |
| - Address: address, |
74 |
| - Protocol: protocol, |
75 |
| - } |
| 68 | + |
| 69 | + res := &boardAttachResult{ |
| 70 | + Fqbn: newDefaults.GetDefaultFqbn(), |
76 | 71 | }
|
77 |
| - if fqbn != "" { |
78 |
| - if err := sk.SetDefaultFQBN(fqbn); err != nil { |
79 |
| - feedback.Fatal(fmt.Sprintf("%s: %s", tr("Error saving sketch metadata"), err), feedback.ErrGeneric) |
| 72 | + if newDefaults.GetDefaultPortAddress() != "" { |
| 73 | + res.Port = &boardAttachPortResult{ |
| 74 | + Address: newDefaults.GetDefaultPortAddress(), |
| 75 | + Protocol: newDefaults.GetDefaultPortProtocol(), |
80 | 76 | }
|
81 |
| - current.Fqbn = fqbn |
82 | 77 | }
|
83 |
| - |
84 |
| - feedback.PrintResult(current) |
| 78 | + feedback.PrintResult(res) |
85 | 79 | }
|
86 | 80 |
|
87 | 81 | type boardAttachPortResult struct {
|
|
0 commit comments