Skip to content

Commit a2d9f80

Browse files
committed
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

Lines changed: 6 additions & 8 deletions
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

Lines changed: 9 additions & 12 deletions
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 [email protected].
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

Lines changed: 1 addition & 1 deletion
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 [email protected].
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

Lines changed: 1 addition & 1 deletion
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 [email protected].
1515

16-
package sketch
16+
package commands
1717

1818
import (
1919
"context"

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

Lines changed: 1 addition & 4 deletions
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 [email protected].
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

Lines changed: 1 addition & 1 deletion
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 [email protected].
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

Lines changed: 1 addition & 1 deletion
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 [email protected].
1515

16-
package sketch
16+
package commands
1717

1818
import (
1919
"context"

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

Lines changed: 1 addition & 1 deletion
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 [email protected].
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

Lines changed: 1 addition & 1 deletion
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 [email protected].
1515

16-
package sketch
16+
package commands
1717

1818
import (
1919
"context"

0 commit comments

Comments
 (0)