Skip to content

Commit 8f65d3a

Browse files
committed
Let instance commands require an *rpc.Instance
Removed the shorthand of the InstanceCommand interface. This makes the API more coherent among the `commands` instance handling.
1 parent 1e51cdc commit 8f65d3a

29 files changed

+41
-47
lines changed

commands/board/details.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import (
2828
// Details returns all details for a board including tools and HW identifiers.
2929
// This command basically gather al the information and translates it into the required grpc struct properties
3030
func Details(ctx context.Context, req *rpc.BoardDetailsRequest) (*rpc.BoardDetailsResponse, error) {
31-
pme, release := commands.GetPackageManagerExplorer(req)
31+
pme, release := commands.GetPackageManagerExplorer(req.GetInstance())
3232
if pme == nil {
3333
return nil, &arduino.InvalidInstanceError{}
3434
}

commands/board/list.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ func identify(pme *packagemanager.Explorer, port *discovery.Port) ([]*rpc.BoardL
203203
// In case of errors partial results from discoveries that didn't fail
204204
// are returned.
205205
func List(req *rpc.BoardListRequest) (r []*rpc.DetectedPort, discoveryStartErrors []error, e error) {
206-
pme, release := commands.GetPackageManagerExplorer(req)
206+
pme, release := commands.GetPackageManagerExplorer(req.GetInstance())
207207
if pme == nil {
208208
return nil, nil, &arduino.InvalidInstanceError{}
209209
}
@@ -258,7 +258,7 @@ func hasMatchingBoard(b *rpc.DetectedPort, fqbnFilter *cores.FQBN) bool {
258258

259259
// Watch returns a channel that receives boards connection and disconnection events.
260260
func Watch(ctx context.Context, req *rpc.BoardListWatchRequest) (<-chan *rpc.BoardListWatchResponse, error) {
261-
pme, release := commands.GetPackageManagerExplorer(req)
261+
pme, release := commands.GetPackageManagerExplorer(req.GetInstance())
262262
if pme == nil {
263263
return nil, &arduino.InvalidInstanceError{}
264264
}

commands/board/listall.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import (
2929

3030
// ListAll FIXMEDOC
3131
func ListAll(ctx context.Context, req *rpc.BoardListAllRequest) (*rpc.BoardListAllResponse, error) {
32-
pme, release := commands.GetPackageManagerExplorer(req)
32+
pme, release := commands.GetPackageManagerExplorer(req.GetInstance())
3333
if pme == nil {
3434
return nil, &arduino.InvalidInstanceError{}
3535
}

commands/board/search.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import (
3131
// installed. Note that platforms that are not installed don't include boards' FQBNs.
3232
// If no search argument is used all boards are returned.
3333
func Search(ctx context.Context, req *rpc.BoardSearchRequest) (*rpc.BoardSearchResponse, error) {
34-
pme, release := commands.GetPackageManagerExplorer(req)
34+
pme, release := commands.GetPackageManagerExplorer(req.GetInstance())
3535
if pme == nil {
3636
return nil, &arduino.InvalidInstanceError{}
3737
}

commands/compile/compile.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,13 @@ func Compile(ctx context.Context, req *rpc.CompileRequest, outStream, errStream
5757
exportBinaries = reqExportBinaries.Value
5858
}
5959

60-
pme, release := commands.GetPackageManagerExplorer(req)
60+
pme, release := commands.GetPackageManagerExplorer(req.GetInstance())
6161
if pme == nil {
6262
return nil, &arduino.InvalidInstanceError{}
6363
}
6464
defer release()
6565

66-
lm := commands.GetLibraryManager(req)
66+
lm := commands.GetLibraryManager(req.GetInstance())
6767
if lm == nil {
6868
return nil, &arduino.InvalidInstanceError{}
6969
}

commands/core/download.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ var tr = i18n.Tr
2929

3030
// PlatformDownload FIXMEDOC
3131
func PlatformDownload(ctx context.Context, req *rpc.PlatformDownloadRequest, downloadCB rpc.DownloadProgressCB) (*rpc.PlatformDownloadResponse, error) {
32-
pme, release := commands.GetPackageManagerExplorer(req)
32+
pme, release := commands.GetPackageManagerExplorer(req.GetInstance())
3333
if pme == nil {
3434
return nil, &arduino.InvalidInstanceError{}
3535
}

commands/core/install.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import (
2828
// PlatformInstall FIXMEDOC
2929
func PlatformInstall(ctx context.Context, req *rpc.PlatformInstallRequest, downloadCB rpc.DownloadProgressCB, taskCB rpc.TaskProgressCB) (*rpc.PlatformInstallResponse, error) {
3030
install := func() error {
31-
pme, release := commands.GetPackageManagerExplorer(req)
31+
pme, release := commands.GetPackageManagerExplorer(req.GetInstance())
3232
if pme == nil {
3333
return &arduino.InvalidInstanceError{}
3434
}

commands/core/list.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import (
2828
// PlatformList returns a list of installed platforms, optionally filtered by
2929
// those requiring an update.
3030
func PlatformList(req *rpc.PlatformListRequest) (*rpc.PlatformListResponse, error) {
31-
pme, release := commands.GetPackageManagerExplorer(req)
31+
pme, release := commands.GetPackageManagerExplorer(req.GetInstance())
3232
if pme == nil {
3333
return nil, &arduino.InvalidInstanceError{}
3434
}

commands/core/search.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import (
2929

3030
// PlatformSearch FIXMEDOC
3131
func PlatformSearch(req *rpc.PlatformSearchRequest) (*rpc.PlatformSearchResponse, error) {
32-
pme, release := commands.GetPackageManagerExplorer(req)
32+
pme, release := commands.GetPackageManagerExplorer(req.GetInstance())
3333
if pme == nil {
3434
return nil, &arduino.InvalidInstanceError{}
3535
}

commands/core/uninstall.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ func PlatformUninstall(ctx context.Context, req *rpc.PlatformUninstallRequest, t
3737

3838
// platformUninstall is the implementation of platform unistaller
3939
func platformUninstall(ctx context.Context, req *rpc.PlatformUninstallRequest, taskCB rpc.TaskProgressCB) error {
40-
pme, release := commands.GetPackageManagerExplorer(req)
40+
pme, release := commands.GetPackageManagerExplorer(req.GetInstance())
4141
if pme == nil {
4242
return &arduino.InvalidInstanceError{}
4343
}

commands/core/upgrade.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import (
2929
// PlatformUpgrade FIXMEDOC
3030
func PlatformUpgrade(ctx context.Context, req *rpc.PlatformUpgradeRequest, downloadCB rpc.DownloadProgressCB, taskCB rpc.TaskProgressCB) (*rpc.PlatformUpgradeResponse, error) {
3131
upgrade := func() (*cores.PlatformRelease, error) {
32-
pme, release := commands.GetPackageManagerExplorer(req)
32+
pme, release := commands.GetPackageManagerExplorer(req.GetInstance())
3333
if pme == nil {
3434
return nil, &arduino.InvalidInstanceError{}
3535
}

commands/debug/debug.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ var tr = i18n.Tr
4545
func Debug(ctx context.Context, req *rpc.GetDebugConfigRequest, inStream io.Reader, out io.Writer, interrupt <-chan os.Signal) (*rpc.DebugResponse, error) {
4646

4747
// Get debugging command line to run debugger
48-
pme, release := commands.GetPackageManagerExplorer(req)
48+
pme, release := commands.GetPackageManagerExplorer(req.GetInstance())
4949
if pme == nil {
5050
return nil, &arduino.InvalidInstanceError{}
5151
}

commands/debug/debug_info.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ import (
3535

3636
// GetDebugConfig returns metadata to start debugging with the specified board
3737
func GetDebugConfig(ctx context.Context, req *rpc.GetDebugConfigRequest) (*rpc.GetDebugConfigResponse, error) {
38-
pme, release := commands.GetPackageManagerExplorer(req)
38+
pme, release := commands.GetPackageManagerExplorer(req.GetInstance())
3939
if pme == nil {
4040
return nil, &arduino.InvalidInstanceError{}
4141
}

commands/instances.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,8 @@ func (c *coreInstancesContainer) RemoveID(id int32) bool {
102102
// GetPackageManager returns a PackageManager. If the package manager is not found
103103
// (because the instance is invalid or has been destroyed), nil is returned.
104104
// Deprecated: use GetPackageManagerExplorer instead.
105-
func GetPackageManager(instance rpc.InstanceCommand) *packagemanager.PackageManager {
106-
i := instances.GetInstance(instance.GetInstance().GetId())
105+
func GetPackageManager(instance *rpc.Instance) *packagemanager.PackageManager {
106+
i := instances.GetInstance(instance.GetId())
107107
if i == nil {
108108
return nil
109109
}
@@ -113,7 +113,7 @@ func GetPackageManager(instance rpc.InstanceCommand) *packagemanager.PackageMana
113113
// GetPackageManagerExplorer returns a new package manager Explorer. The
114114
// explorer holds a read lock on the underlying PackageManager and it should
115115
// be released by calling the returned "release" function.
116-
func GetPackageManagerExplorer(req rpc.InstanceCommand) (explorer *packagemanager.Explorer, release func()) {
116+
func GetPackageManagerExplorer(req *rpc.Instance) (explorer *packagemanager.Explorer, release func()) {
117117
pm := GetPackageManager(req)
118118
if pm == nil {
119119
return nil, nil
@@ -122,8 +122,8 @@ func GetPackageManagerExplorer(req rpc.InstanceCommand) (explorer *packagemanage
122122
}
123123

124124
// GetLibraryManager returns the library manager for the given instance.
125-
func GetLibraryManager(req rpc.InstanceCommand) *librariesmanager.LibrariesManager {
126-
i := instances.GetInstance(req.GetInstance().GetId())
125+
func GetLibraryManager(req *rpc.Instance) *librariesmanager.LibrariesManager {
126+
i := instances.GetInstance(req.GetId())
127127
if i == nil {
128128
return nil
129129
}
@@ -494,7 +494,7 @@ func Destroy(ctx context.Context, req *rpc.DestroyRequest) (*rpc.DestroyResponse
494494
// UpdateLibrariesIndex updates the library_index.json
495495
func UpdateLibrariesIndex(ctx context.Context, req *rpc.UpdateLibrariesIndexRequest, downloadCB rpc.DownloadProgressCB) error {
496496
logrus.Info("Updating libraries index")
497-
lm := GetLibraryManager(req)
497+
lm := GetLibraryManager(req.GetInstance())
498498
if lm == nil {
499499
return &arduino.InvalidInstanceError{}
500500
}

commands/lib/download.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ var tr = i18n.Tr
3535
func LibraryDownload(ctx context.Context, req *rpc.LibraryDownloadRequest, downloadCB rpc.DownloadProgressCB) (*rpc.LibraryDownloadResponse, error) {
3636
logrus.Info("Executing `arduino-cli lib download`")
3737

38-
lm := commands.GetLibraryManager(req)
38+
lm := commands.GetLibraryManager(req.GetInstance())
3939
if lm == nil {
4040
return nil, &arduino.InvalidInstanceError{}
4141
}

commands/lib/install.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ import (
3232

3333
// LibraryInstall resolves the library dependencies, then downloads and installs the libraries into the install location.
3434
func LibraryInstall(ctx context.Context, req *rpc.LibraryInstallRequest, downloadCB rpc.DownloadProgressCB, taskCB rpc.TaskProgressCB) error {
35-
lm := commands.GetLibraryManager(req)
35+
lm := commands.GetLibraryManager(req.GetInstance())
3636
if lm == nil {
3737
return &arduino.InvalidInstanceError{}
3838
}
@@ -143,7 +143,7 @@ func installLibrary(lm *librariesmanager.LibrariesManager, libRelease *libraries
143143

144144
// ZipLibraryInstall FIXMEDOC
145145
func ZipLibraryInstall(ctx context.Context, req *rpc.ZipLibraryInstallRequest, taskCB rpc.TaskProgressCB) error {
146-
lm := commands.GetLibraryManager(req)
146+
lm := commands.GetLibraryManager(req.GetInstance())
147147
if err := lm.InstallZipLib(ctx, paths.New(req.Path), req.Overwrite); err != nil {
148148
return &arduino.FailedLibraryInstallError{Cause: err}
149149
}
@@ -153,7 +153,7 @@ func ZipLibraryInstall(ctx context.Context, req *rpc.ZipLibraryInstallRequest, t
153153

154154
// GitLibraryInstall FIXMEDOC
155155
func GitLibraryInstall(ctx context.Context, req *rpc.GitLibraryInstallRequest, taskCB rpc.TaskProgressCB) error {
156-
lm := commands.GetLibraryManager(req)
156+
lm := commands.GetLibraryManager(req.GetInstance())
157157
if err := lm.InstallGitLib(req.Url, req.Overwrite); err != nil {
158158
return &arduino.FailedLibraryInstallError{Cause: err}
159159
}

commands/lib/list.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,13 @@ type installedLib struct {
3636

3737
// LibraryList FIXMEDOC
3838
func LibraryList(ctx context.Context, req *rpc.LibraryListRequest) (*rpc.LibraryListResponse, error) {
39-
pme, release := commands.GetPackageManagerExplorer(req)
39+
pme, release := commands.GetPackageManagerExplorer(req.GetInstance())
4040
if pme == nil {
4141
return nil, &arduino.InvalidInstanceError{}
4242
}
4343
defer release()
4444

45-
lm := commands.GetLibraryManager(req)
45+
lm := commands.GetLibraryManager(req.GetInstance())
4646
if lm == nil {
4747
return nil, &arduino.InvalidInstanceError{}
4848
}

commands/lib/resolve_deps.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import (
2828

2929
// LibraryResolveDependencies FIXMEDOC
3030
func LibraryResolveDependencies(ctx context.Context, req *rpc.LibraryResolveDependenciesRequest) (*rpc.LibraryResolveDependenciesResponse, error) {
31-
lm := commands.GetLibraryManager(req)
31+
lm := commands.GetLibraryManager(req.GetInstance())
3232
if lm == nil {
3333
return nil, &arduino.InvalidInstanceError{}
3434
}

commands/lib/search.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import (
3131

3232
// LibrarySearch FIXMEDOC
3333
func LibrarySearch(ctx context.Context, req *rpc.LibrarySearchRequest) (*rpc.LibrarySearchResponse, error) {
34-
lm := commands.GetLibraryManager(req)
34+
lm := commands.GetLibraryManager(req.GetInstance())
3535
if lm == nil {
3636
return nil, &arduino.InvalidInstanceError{}
3737
}

commands/lib/uninstall.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import (
2727

2828
// LibraryUninstall FIXMEDOC
2929
func LibraryUninstall(ctx context.Context, req *rpc.LibraryUninstallRequest, taskCB rpc.TaskProgressCB) error {
30-
lm := commands.GetLibraryManager(req)
30+
lm := commands.GetLibraryManager(req.GetInstance())
3131
ref, err := createLibIndexReference(lm, req)
3232
if err != nil {
3333
return &arduino.InvalidLibraryError{Cause: err}

commands/lib/upgrade.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import (
2525

2626
// LibraryUpgradeAll upgrades all the available libraries
2727
func LibraryUpgradeAll(req *rpc.LibraryUpgradeAllRequest, downloadCB rpc.DownloadProgressCB, taskCB rpc.TaskProgressCB) error {
28-
lm := commands.GetLibraryManager(req)
28+
lm := commands.GetLibraryManager(req.GetInstance())
2929
if lm == nil {
3030
return &arduino.InvalidInstanceError{}
3131
}
@@ -43,7 +43,7 @@ func LibraryUpgradeAll(req *rpc.LibraryUpgradeAllRequest, downloadCB rpc.Downloa
4343

4444
// LibraryUpgrade upgrades a library
4545
func LibraryUpgrade(ctx context.Context, req *rpc.LibraryUpgradeRequest, downloadCB rpc.DownloadProgressCB, taskCB rpc.TaskProgressCB) error {
46-
lm := commands.GetLibraryManager(req)
46+
lm := commands.GetLibraryManager(req.GetInstance())
4747
if lm == nil {
4848
return &arduino.InvalidInstanceError{}
4949
}

commands/monitor/monitor.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ func (p *PortProxy) Close() error {
6161
// Monitor opens a communication port. It returns a PortProxy to communicate with the port and a PortDescriptor
6262
// that describes the available configuration settings.
6363
func Monitor(ctx context.Context, req *rpc.MonitorRequest) (*PortProxy, *pluggableMonitor.PortDescriptor, error) {
64-
pme, release := commands.GetPackageManagerExplorer(req)
64+
pme, release := commands.GetPackageManagerExplorer(req.GetInstance())
6565
if pme == nil {
6666
return nil, nil, &arduino.InvalidInstanceError{}
6767
}

commands/monitor/settings.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import (
2626

2727
// EnumerateMonitorPortSettings returns a description of the configuration settings of a monitor port
2828
func EnumerateMonitorPortSettings(ctx context.Context, req *rpc.EnumerateMonitorPortSettingsRequest) (*rpc.EnumerateMonitorPortSettingsResponse, error) {
29-
pme, release := commands.GetPackageManagerExplorer(req)
29+
pme, release := commands.GetPackageManagerExplorer(req.GetInstance())
3030
if pme == nil {
3131
return nil, &arduino.InvalidInstanceError{}
3232
}

commands/upload/burnbootloader.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ func BurnBootloader(ctx context.Context, req *rpc.BurnBootloaderRequest, outStre
3333
WithField("programmer", req.GetProgrammer()).
3434
Trace("BurnBootloader started", req.GetFqbn())
3535

36-
pme, release := commands.GetPackageManagerExplorer(req)
36+
pme, release := commands.GetPackageManagerExplorer(req.GetInstance())
3737
if pme == nil {
3838
return nil, &arduino.InvalidInstanceError{}
3939
}

commands/upload/programmers_list.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import (
2626

2727
// ListProgrammersAvailableForUpload FIXMEDOC
2828
func ListProgrammersAvailableForUpload(ctx context.Context, req *rpc.ListProgrammersAvailableForUploadRequest) (*rpc.ListProgrammersAvailableForUploadResponse, error) {
29-
pme, release := commands.GetPackageManagerExplorer(req)
29+
pme, release := commands.GetPackageManagerExplorer(req.GetInstance())
3030
if pme == nil {
3131
return nil, &arduino.InvalidInstanceError{}
3232
}

commands/upload/upload.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ func SupportedUserFields(ctx context.Context, req *rpc.SupportedUserFieldsReques
5050
return nil, &arduino.MissingPortProtocolError{}
5151
}
5252

53-
pme, release := commands.GetPackageManagerExplorer(req)
53+
pme, release := commands.GetPackageManagerExplorer(req.GetInstance())
5454
defer release()
5555

5656
if pme == nil {
@@ -137,7 +137,7 @@ func Upload(ctx context.Context, req *rpc.UploadRequest, outStream io.Writer, er
137137
return nil, &arduino.CantOpenSketchError{Cause: err}
138138
}
139139

140-
pme, pmeRelease := commands.GetPackageManagerExplorer(req)
140+
pme, pmeRelease := commands.GetPackageManagerExplorer(req.GetInstance())
141141
if pme == nil {
142142
return nil, &arduino.InvalidInstanceError{}
143143
}

internal/cli/arguments/completion.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ func GetInstalledProtocols() []string {
5252
inst := instance.CreateAndInit()
5353

5454
// FIXME: We must not access PackageManager directly here but use one of the commands.* functions
55-
pme, release := commands.GetPackageManagerExplorer(&rpc.BoardListAllRequest{Instance: inst})
55+
pme, release := commands.GetPackageManagerExplorer(inst)
5656
if pme == nil {
5757
return nil // should never happen...
5858
}
@@ -95,7 +95,7 @@ func GetInstalledProgrammers() []string {
9595
list, _ := board.ListAll(context.Background(), listAllReq)
9696

9797
// FIXME: We must not access PackageManager directly here but use one of the commands.* functions
98-
pme, release := commands.GetPackageManagerExplorer(listAllReq)
98+
pme, release := commands.GetPackageManagerExplorer(inst)
9999
if pme == nil {
100100
return nil // should never happen...
101101
}

internal/cli/arguments/port.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ func (p *Port) GetPort(instance *rpc.Instance, defaultAddress, defaultProtocol s
8989
logrus.WithField("port", address).Tracef("Upload port")
9090

9191
// FIXME: We must not access PackageManager directly here but use one of the commands.* functions
92-
pme, release := commands.GetPackageManagerExplorer(&rpc.BoardListAllRequest{Instance: instance})
92+
pme, release := commands.GetPackageManagerExplorer(instance)
9393
if pme == nil {
9494
return nil, &arduino.InvalidInstanceError{}
9595
}

rpc/cc/arduino/cli/commands/v1/common.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,3 @@ func (d DownloadProgressCB) End(success bool, message string) {
5656

5757
// TaskProgressCB is a callback to receive progress messages
5858
type TaskProgressCB func(msg *TaskProgress)
59-
60-
// InstanceCommand is an interface that represents a gRPC command with
61-
// a gRPC Instance.
62-
type InstanceCommand interface {
63-
GetInstance() *Instance
64-
}

0 commit comments

Comments
 (0)