Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit a2d9f80

Browse files
committedMar 13, 2024
Moved a batch of function from commands/* subpackage to commands (part 4)
1 parent f40ff3a commit a2d9f80

19 files changed

+39
-50
lines changed
 

‎commands/service.go

+6-8
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@ import (
2323
"sync/atomic"
2424

2525
"github.com/arduino/arduino-cli/commands/cmderrors"
26-
"github.com/arduino/arduino-cli/commands/monitor"
27-
"github.com/arduino/arduino-cli/commands/sketch"
2826
rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1"
2927
"github.com/sirupsen/logrus"
3028
"google.golang.org/grpc/metadata"
@@ -154,19 +152,19 @@ func (s *ArduinoCoreServerImpl) Version(ctx context.Context, req *rpc.VersionReq
154152

155153
// NewSketch FIXMEDOC
156154
func (s *ArduinoCoreServerImpl) NewSketch(ctx context.Context, req *rpc.NewSketchRequest) (*rpc.NewSketchResponse, error) {
157-
resp, err := sketch.NewSketch(ctx, req)
155+
resp, err := NewSketch(ctx, req)
158156
return resp, convertErrorToRPCStatus(err)
159157
}
160158

161159
// LoadSketch FIXMEDOC
162160
func (s *ArduinoCoreServerImpl) LoadSketch(ctx context.Context, req *rpc.LoadSketchRequest) (*rpc.LoadSketchResponse, error) {
163-
resp, err := sketch.LoadSketch(ctx, req)
161+
resp, err := LoadSketch(ctx, req)
164162
return &rpc.LoadSketchResponse{Sketch: resp}, convertErrorToRPCStatus(err)
165163
}
166164

167165
// SetSketchDefaults FIXMEDOC
168166
func (s *ArduinoCoreServerImpl) SetSketchDefaults(ctx context.Context, req *rpc.SetSketchDefaultsRequest) (*rpc.SetSketchDefaultsResponse, error) {
169-
resp, err := sketch.SetSketchDefaults(ctx, req)
167+
resp, err := SetSketchDefaults(ctx, req)
170168
return resp, convertErrorToRPCStatus(err)
171169
}
172170

@@ -429,7 +427,7 @@ func (s *ArduinoCoreServerImpl) LibraryList(ctx context.Context, req *rpc.Librar
429427

430428
// ArchiveSketch FIXMEDOC
431429
func (s *ArduinoCoreServerImpl) ArchiveSketch(ctx context.Context, req *rpc.ArchiveSketchRequest) (*rpc.ArchiveSketchResponse, error) {
432-
resp, err := sketch.ArchiveSketch(ctx, req)
430+
resp, err := ArchiveSketch(ctx, req)
433431
return resp, convertErrorToRPCStatus(err)
434432
}
435433

@@ -455,7 +453,7 @@ func (s *ArduinoCoreServerImpl) GitLibraryInstall(req *rpc.GitLibraryInstallRequ
455453

456454
// EnumerateMonitorPortSettings FIXMEDOC
457455
func (s *ArduinoCoreServerImpl) EnumerateMonitorPortSettings(ctx context.Context, req *rpc.EnumerateMonitorPortSettingsRequest) (*rpc.EnumerateMonitorPortSettingsResponse, error) {
458-
resp, err := monitor.EnumerateMonitorPortSettings(ctx, req)
456+
resp, err := EnumerateMonitorPortSettings(ctx, req)
459457
return resp, convertErrorToRPCStatus(err)
460458
}
461459

@@ -473,7 +471,7 @@ func (s *ArduinoCoreServerImpl) Monitor(stream rpc.ArduinoCoreService_MonitorSer
473471
if openReq == nil {
474472
return &cmderrors.InvalidInstanceError{}
475473
}
476-
portProxy, _, err := monitor.Monitor(stream.Context(), openReq)
474+
portProxy, _, err := Monitor(stream.Context(), openReq)
477475
if err != nil {
478476
return err
479477
}

‎commands/monitor/monitor.go renamed to ‎commands/service_monitor.go

+9-12
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
// Arduino software without disclosing the source code of your own applications.
1414
// To purchase a commercial license, send an email to license@arduino.cc.
1515

16-
package monitor
16+
package commands
1717

1818
import (
1919
"context"
@@ -25,42 +25,39 @@ import (
2525
"github.com/arduino/arduino-cli/internal/arduino/cores"
2626
"github.com/arduino/arduino-cli/internal/arduino/cores/packagemanager"
2727
pluggableMonitor "github.com/arduino/arduino-cli/internal/arduino/monitor"
28-
"github.com/arduino/arduino-cli/internal/i18n"
2928
rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1"
3029
"github.com/arduino/go-properties-orderedmap"
3130
"github.com/sirupsen/logrus"
3231
)
3332

34-
var tr = i18n.Tr
35-
36-
// PortProxy is an io.ReadWriteCloser that maps into the monitor port of the board
37-
type PortProxy struct {
33+
// portProxy is an io.ReadWriteCloser that maps into the monitor port of the board
34+
type portProxy struct {
3835
rw io.ReadWriter
3936
changeSettingsCB func(setting, value string) error
4037
closeCB func() error
4138
}
4239

43-
func (p *PortProxy) Read(buff []byte) (int, error) {
40+
func (p *portProxy) Read(buff []byte) (int, error) {
4441
return p.rw.Read(buff)
4542
}
4643

47-
func (p *PortProxy) Write(buff []byte) (int, error) {
44+
func (p *portProxy) Write(buff []byte) (int, error) {
4845
return p.rw.Write(buff)
4946
}
5047

5148
// Config sets the port configuration setting to the specified value
52-
func (p *PortProxy) Config(setting, value string) error {
49+
func (p *portProxy) Config(setting, value string) error {
5350
return p.changeSettingsCB(setting, value)
5451
}
5552

5653
// Close the port
57-
func (p *PortProxy) Close() error {
54+
func (p *portProxy) Close() error {
5855
return p.closeCB()
5956
}
6057

6158
// Monitor opens a communication port. It returns a PortProxy to communicate with the port and a PortDescriptor
6259
// that describes the available configuration settings.
63-
func Monitor(ctx context.Context, req *rpc.MonitorPortOpenRequest) (*PortProxy, *pluggableMonitor.PortDescriptor, error) {
60+
func Monitor(ctx context.Context, req *rpc.MonitorPortOpenRequest) (*portProxy, *pluggableMonitor.PortDescriptor, error) {
6461
pme, release, err := instances.GetPackageManagerExplorer(req.GetInstance())
6562
if err != nil {
6663
return nil, nil, err
@@ -103,7 +100,7 @@ func Monitor(ctx context.Context, req *rpc.MonitorPortOpenRequest) (*PortProxy,
103100
}
104101

105102
logrus.Infof("Port %s successfully opened", req.GetPort().GetAddress())
106-
return &PortProxy{
103+
return &portProxy{
107104
rw: monIO,
108105
changeSettingsCB: m.Configure,
109106
closeCB: func() error {

‎commands/monitor/settings.go renamed to ‎commands/service_monitor_settings.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
// Arduino software without disclosing the source code of your own applications.
1414
// To purchase a commercial license, send an email to license@arduino.cc.
1515

16-
package monitor
16+
package commands
1717

1818
import (
1919
"context"

‎commands/sketch/set_defaults.go renamed to ‎commands/service_set_sketch_defaults.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
// Arduino software without disclosing the source code of your own applications.
1414
// To purchase a commercial license, send an email to license@arduino.cc.
1515

16-
package sketch
16+
package commands
1717

1818
import (
1919
"context"

‎commands/sketch/archive.go renamed to ‎commands/service_sketch_archive.go

+1-4
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
// Arduino software without disclosing the source code of your own applications.
1414
// To purchase a commercial license, send an email to license@arduino.cc.
1515

16-
package sketch
16+
package commands
1717

1818
import (
1919
"archive/zip"
@@ -24,13 +24,10 @@ import (
2424

2525
"github.com/arduino/arduino-cli/commands/cmderrors"
2626
"github.com/arduino/arduino-cli/internal/arduino/sketch"
27-
"github.com/arduino/arduino-cli/internal/i18n"
2827
rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1"
2928
paths "github.com/arduino/go-paths-helper"
3029
)
3130

32-
var tr = i18n.Tr
33-
3431
// ArchiveSketch FIXMEDOC
3532
func ArchiveSketch(ctx context.Context, req *rpc.ArchiveSketchRequest) (*rpc.ArchiveSketchResponse, error) {
3633
// sketchName is the name of the sketch without extension, for example "MySketch"

‎commands/sketch/load.go renamed to ‎commands/service_sketch_load.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
// Arduino software without disclosing the source code of your own applications.
1414
// To purchase a commercial license, send an email to license@arduino.cc.
1515

16-
package sketch
16+
package commands
1717

1818
import (
1919
"context"

‎commands/sketch/load_test.go renamed to ‎commands/service_sketch_load_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
// Arduino software without disclosing the source code of your own applications.
1414
// To purchase a commercial license, send an email to license@arduino.cc.
1515

16-
package sketch
16+
package commands
1717

1818
import (
1919
"context"

‎commands/sketch/new.go renamed to ‎commands/service_sketch_new.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
// Arduino software without disclosing the source code of your own applications.
1414
// To purchase a commercial license, send an email to license@arduino.cc.
1515

16-
package sketch
16+
package commands
1717

1818
import (
1919
"context"

‎commands/sketch/new_test.go renamed to ‎commands/service_sketch_new_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
// Arduino software without disclosing the source code of your own applications.
1414
// To purchase a commercial license, send an email to license@arduino.cc.
1515

16-
package sketch
16+
package commands
1717

1818
import (
1919
"context"

‎internal/cli/arguments/sketch.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ package arguments
1818
import (
1919
"context"
2020

21-
"github.com/arduino/arduino-cli/commands/sketch"
21+
"github.com/arduino/arduino-cli/commands"
2222
f "github.com/arduino/arduino-cli/internal/algorithms"
2323
"github.com/arduino/arduino-cli/internal/cli/feedback"
2424
rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1"
@@ -52,7 +52,7 @@ func GetSketchProfiles(sketchPath string) []string {
5252
return nil
5353
}
5454
}
55-
sk, err := sketch.LoadSketch(context.Background(), &rpc.LoadSketchRequest{SketchPath: sketchPath})
55+
sk, err := commands.LoadSketch(context.Background(), &rpc.LoadSketchRequest{SketchPath: sketchPath})
5656
if err != nil {
5757
return nil
5858
}

‎internal/cli/board/attach.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import (
2020
"fmt"
2121
"os"
2222

23-
"github.com/arduino/arduino-cli/commands/sketch"
23+
"github.com/arduino/arduino-cli/commands"
2424
"github.com/arduino/arduino-cli/internal/cli/arguments"
2525
"github.com/arduino/arduino-cli/internal/cli/feedback"
2626
rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1"
@@ -59,7 +59,7 @@ func runAttachCommand(path string, port *arguments.Port, fqbn string, programmer
5959
sketchPath := arguments.InitSketchPath(path)
6060

6161
portAddress, portProtocol, _ := port.GetPortAddressAndProtocol(nil, "", "")
62-
newDefaults, err := sketch.SetSketchDefaults(context.Background(), &rpc.SetSketchDefaultsRequest{
62+
newDefaults, err := commands.SetSketchDefaults(context.Background(), &rpc.SetSketchDefaultsRequest{
6363
SketchPath: sketchPath.String(),
6464
DefaultFqbn: fqbn,
6565
DefaultProgrammer: programmer.GetProgrammer(),

‎internal/cli/compile/compile.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ import (
2626

2727
"github.com/arduino/arduino-cli/commands"
2828
"github.com/arduino/arduino-cli/commands/cmderrors"
29-
"github.com/arduino/arduino-cli/commands/sketch"
3029
"github.com/arduino/arduino-cli/internal/cli/arguments"
3130
"github.com/arduino/arduino-cli/internal/cli/configuration"
3231
"github.com/arduino/arduino-cli/internal/cli/feedback"
@@ -159,7 +158,7 @@ func runCompileCommand(cmd *cobra.Command, args []string) {
159158
}
160159

161160
sketchPath := arguments.InitSketchPath(path)
162-
sk, err := sketch.LoadSketch(context.Background(), &rpc.LoadSketchRequest{SketchPath: sketchPath.String()})
161+
sk, err := commands.LoadSketch(context.Background(), &rpc.LoadSketchRequest{SketchPath: sketchPath.String()})
163162
if err != nil {
164163
feedback.FatalError(err, feedback.ErrGeneric)
165164
}

‎internal/cli/debug/debug.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ import (
2222
"os"
2323
"os/signal"
2424

25+
"github.com/arduino/arduino-cli/commands"
2526
"github.com/arduino/arduino-cli/commands/cmderrors"
2627
"github.com/arduino/arduino-cli/commands/debug"
27-
"github.com/arduino/arduino-cli/commands/sketch"
2828
"github.com/arduino/arduino-cli/internal/cli/arguments"
2929
"github.com/arduino/arduino-cli/internal/cli/feedback"
3030
"github.com/arduino/arduino-cli/internal/cli/feedback/table"
@@ -83,7 +83,7 @@ func runDebugCommand(args []string, portArgs *arguments.Port, fqbnArg *arguments
8383
}
8484

8585
sketchPath := arguments.InitSketchPath(path)
86-
sk, err := sketch.LoadSketch(context.Background(), &rpc.LoadSketchRequest{SketchPath: sketchPath.String()})
86+
sk, err := commands.LoadSketch(context.Background(), &rpc.LoadSketchRequest{SketchPath: sketchPath.String()})
8787
if err != nil {
8888
feedback.FatalError(err, feedback.ErrGeneric)
8989
}

‎internal/cli/monitor/monitor.go

+4-5
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@ import (
2626
"strings"
2727
"time"
2828

29-
"github.com/arduino/arduino-cli/commands/monitor"
30-
sk "github.com/arduino/arduino-cli/commands/sketch"
29+
"github.com/arduino/arduino-cli/commands"
3130
"github.com/arduino/arduino-cli/internal/cli/arguments"
3231
"github.com/arduino/arduino-cli/internal/cli/feedback"
3332
"github.com/arduino/arduino-cli/internal/cli/feedback/result"
@@ -104,7 +103,7 @@ func runMonitorCmd(
104103
// If only --port is set we read the fqbn in the following order: default_fqbn -> discovery
105104
// If only --fqbn is set we read the port in the following order: default_port
106105
sketchPath := arguments.InitSketchPath(sketchPathArg)
107-
sketch, err := sk.LoadSketch(context.Background(), &rpc.LoadSketchRequest{SketchPath: sketchPath.String()})
106+
sketch, err := commands.LoadSketch(context.Background(), &rpc.LoadSketchRequest{SketchPath: sketchPath.String()})
108107
if err != nil && !portArgs.IsPortFlagSet() {
109108
feedback.Fatal(
110109
tr("Error getting default port from `sketch.yaml`. Check if you're in the correct sketch folder or provide the --port flag: %s", err),
@@ -145,7 +144,7 @@ func runMonitorCmd(
145144
feedback.FatalError(err, feedback.ErrGeneric)
146145
}
147146

148-
enumerateResp, err := monitor.EnumerateMonitorPortSettings(context.Background(), &rpc.EnumerateMonitorPortSettingsRequest{
147+
enumerateResp, err := commands.EnumerateMonitorPortSettings(context.Background(), &rpc.EnumerateMonitorPortSettingsRequest{
149148
Instance: inst,
150149
PortProtocol: portProtocol,
151150
Fqbn: fqbn,
@@ -203,7 +202,7 @@ func runMonitorCmd(
203202
}
204203
}
205204
}
206-
portProxy, _, err := monitor.Monitor(context.Background(), &rpc.MonitorPortOpenRequest{
205+
portProxy, _, err := commands.Monitor(context.Background(), &rpc.MonitorPortOpenRequest{
207206
Instance: inst,
208207
Port: &rpc.Port{Address: portAddress, Protocol: portProtocol},
209208
Fqbn: fqbn,

‎internal/cli/sketch/archive.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import (
2020
"fmt"
2121
"os"
2222

23-
"github.com/arduino/arduino-cli/commands/sketch"
23+
"github.com/arduino/arduino-cli/commands"
2424
"github.com/arduino/arduino-cli/internal/cli/arguments"
2525
"github.com/arduino/arduino-cli/internal/cli/feedback"
2626
rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1"
@@ -66,13 +66,13 @@ func runArchiveCommand(args []string, includeBuildDir bool, overwrite bool) {
6666
}
6767

6868
sketchPath := arguments.InitSketchPath(sketchPathArg)
69-
sk, err := sketch.LoadSketch(context.Background(), &rpc.LoadSketchRequest{SketchPath: sketchPath.String()})
69+
sk, err := commands.LoadSketch(context.Background(), &rpc.LoadSketchRequest{SketchPath: sketchPath.String()})
7070
if err != nil {
7171
feedback.FatalError(err, feedback.ErrGeneric)
7272
}
7373
feedback.WarnAboutDeprecatedFiles(sk)
7474

75-
if _, err := sketch.ArchiveSketch(context.Background(),
75+
if _, err := commands.ArchiveSketch(context.Background(),
7676
&rpc.ArchiveSketchRequest{
7777
SketchPath: sketchPath.String(),
7878
ArchivePath: archivePathArg,

‎internal/cli/sketch/new.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import (
2020
"os"
2121
"strings"
2222

23-
sk "github.com/arduino/arduino-cli/commands/sketch"
23+
"github.com/arduino/arduino-cli/commands"
2424
"github.com/arduino/arduino-cli/internal/arduino/globals"
2525
"github.com/arduino/arduino-cli/internal/cli/feedback"
2626
rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1"
@@ -72,7 +72,7 @@ func runNewCommand(args []string, overwrite bool) {
7272
sketchName = sketchDirPath.Base()
7373
}
7474

75-
_, err = sk.NewSketch(context.Background(), &rpc.NewSketchRequest{
75+
_, err = commands.NewSketch(context.Background(), &rpc.NewSketchRequest{
7676
SketchName: sketchName,
7777
SketchDir: sketchDir,
7878
Overwrite: overwrite,

‎internal/cli/upload/upload.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import (
2424

2525
"github.com/arduino/arduino-cli/commands"
2626
"github.com/arduino/arduino-cli/commands/cmderrors"
27-
sk "github.com/arduino/arduino-cli/commands/sketch"
2827
"github.com/arduino/arduino-cli/internal/cli/arguments"
2928
"github.com/arduino/arduino-cli/internal/cli/feedback"
3029
"github.com/arduino/arduino-cli/internal/cli/feedback/result"
@@ -90,7 +89,7 @@ func runUploadCommand(args []string, uploadFieldsArgs map[string]string) {
9089
path = args[0]
9190
}
9291
sketchPath := arguments.InitSketchPath(path)
93-
sketch, err := sk.LoadSketch(context.Background(), &rpc.LoadSketchRequest{SketchPath: sketchPath.String()})
92+
sketch, err := commands.LoadSketch(context.Background(), &rpc.LoadSketchRequest{SketchPath: sketchPath.String()})
9493
if importDir == "" && importFile == "" {
9594
if err != nil {
9695
feedback.Fatal(tr("Error during Upload: %v", err), feedback.ErrGeneric)

0 commit comments

Comments
 (0)