From bd0eb8c2ddd029e2276170a04172bb8762147b56 Mon Sep 17 00:00:00 2001 From: Alessio Perugini Date: Fri, 10 Nov 2023 18:06:54 +0100 Subject: [PATCH] protogetter: refactor all direct proto access with getter methods --- .../cores/packagemanager/install_uninstall.go | 2 +- arduino/discovery/discovery.go | 16 +++---- arduino/errors.go | 8 ++-- client_example/main.go | 20 ++++---- commands/board/details.go | 14 +++--- commands/board/list.go | 8 ++-- commands/board/list_test.go | 12 ++--- commands/board/listall.go | 2 +- commands/board/search.go | 6 +-- commands/compile/compile.go | 14 +++--- commands/core/download.go | 4 +- commands/core/install.go | 6 +-- commands/core/search.go | 12 ++--- commands/core/search_test.go | 38 +++++++-------- commands/core/uninstall.go | 6 +-- commands/core/upgrade.go | 6 +-- commands/daemon/daemon.go | 4 +- commands/daemon/settings.go | 2 +- commands/daemon/term_example/main.go | 6 +-- commands/debug/debug.go | 10 ++-- commands/debug/debug_info.go | 4 +- commands/lib/install.go | 36 +++++++-------- commands/lib/resolve_deps.go | 2 +- commands/lib/search.go | 6 +-- commands/lib/search_test.go | 14 +++--- commands/lib/uninstall.go | 2 +- commands/lib/upgrade.go | 4 +- commands/monitor/monitor.go | 8 ++-- commands/sketch/archive.go | 8 ++-- commands/sketch/load.go | 2 +- commands/sketch/new.go | 10 ++-- commands/sketch/set_defaults.go | 2 +- commands/upload/upload.go | 4 +- commands/upload/upload_test.go | 24 +++++----- internal/cli/arguments/completion.go | 20 ++++---- internal/cli/arguments/port.go | 8 ++-- internal/cli/arguments/user_fields.go | 4 +- internal/cli/board/search.go | 2 +- internal/cli/compile/compile.go | 14 +++--- internal/cli/core/list.go | 4 +- internal/cli/core/upgrade.go | 12 ++--- internal/cli/debug/debug.go | 24 +++++----- internal/cli/feedback/result/rpc.go | 44 +++++++++--------- internal/cli/instance/instance.go | 12 ++--- internal/cli/lib/examples.go | 4 +- internal/cli/lib/list.go | 2 +- internal/cli/monitor/monitor.go | 16 +++---- internal/cli/upload/upload.go | 16 +++---- internal/integrationtest/arduino-cli.go | 2 +- .../integrationtest/daemon/daemon_test.go | 46 +++++++++---------- .../daemon/download_progress_test.go | 2 +- rpc/cc/arduino/cli/commands/v1/common.go | 10 ++-- 52 files changed, 282 insertions(+), 282 deletions(-) diff --git a/arduino/cores/packagemanager/install_uninstall.go b/arduino/cores/packagemanager/install_uninstall.go index 2f396894fa5..e5aa43a5ad1 100644 --- a/arduino/cores/packagemanager/install_uninstall.go +++ b/arduino/cores/packagemanager/install_uninstall.go @@ -448,7 +448,7 @@ func (pme *Explorer) IsToolRequired(toolRelease *cores.ToolRelease) bool { func skipEmptyMessageTaskProgressCB(taskCB rpc.TaskProgressCB) rpc.TaskProgressCB { return func(msg *rpc.TaskProgress) { - if msg != nil && len(msg.Message) == 0 { + if msg != nil && len(msg.GetMessage()) == 0 { return } taskCB(msg) diff --git a/arduino/discovery/discovery.go b/arduino/discovery/discovery.go index 2e9946d675c..4ba26d91121 100644 --- a/arduino/discovery/discovery.go +++ b/arduino/discovery/discovery.go @@ -125,14 +125,14 @@ func PortFromRPCPort(o *rpc.Port) (p *Port) { return nil } res := &Port{ - Address: o.Address, - AddressLabel: o.Label, - Protocol: o.Protocol, - ProtocolLabel: o.ProtocolLabel, - HardwareID: o.HardwareId, - } - if o.Properties != nil { - res.Properties = properties.NewFromHashmap(o.Properties) + Address: o.GetAddress(), + AddressLabel: o.GetLabel(), + Protocol: o.GetProtocol(), + ProtocolLabel: o.GetProtocolLabel(), + HardwareID: o.GetHardwareId(), + } + if o.GetProperties() != nil { + res.Properties = properties.NewFromHashmap(o.GetProperties()) } return res } diff --git a/arduino/errors.go b/arduino/errors.go index c9f81e8f270..b1618d13ff8 100644 --- a/arduino/errors.go +++ b/arduino/errors.go @@ -134,8 +134,8 @@ type NoBoardsDetectedError struct { func (e *NoBoardsDetectedError) Error() string { return tr( "Please specify an FQBN. The board on port %[1]s with protocol %[2]s can't be identified", - e.Port.Address, - e.Port.Protocol, + e.Port.GetAddress(), + e.Port.GetProtocol(), ) } @@ -154,8 +154,8 @@ type MultipleBoardsDetectedError struct { func (e *MultipleBoardsDetectedError) Error() string { return tr( "Please specify an FQBN. Multiple possible boards detected on port %[1]s with protocol %[2]s", - e.Port.Address, - e.Port.Protocol, + e.Port.GetAddress(), + e.Port.GetProtocol(), ) } diff --git a/client_example/main.go b/client_example/main.go index 23526db43af..a5a3b3672ff 100644 --- a/client_example/main.go +++ b/client_example/main.go @@ -330,7 +330,7 @@ func createInstance(client rpc.ArduinoCoreServiceClient) *rpc.Instance { if err != nil { log.Fatalf("Error creating server instance: %s", err) } - return res.Instance + return res.GetInstance() } func initInstance(client rpc.ArduinoCoreServiceClient, instance *rpc.Instance) { @@ -521,8 +521,8 @@ func callBoardSearch(client rpc.ArduinoCoreServiceClient, instance *rpc.Instance log.Fatalf("Error getting board data: %s\n", err) } - for _, board := range res.Boards { - log.Printf("Board Name: %s, Board Platform: %s\n", board.Name, board.Platform.Metadata.Id) + for _, board := range res.GetBoards() { + log.Printf("Board Name: %s, Board Platform: %s\n", board.GetName(), board.GetPlatform().GetMetadata().GetId()) } } @@ -650,16 +650,16 @@ func callBoardListWatch(client rpc.ArduinoCoreServiceClient, instance *rpc.Insta } else if err != nil { log.Fatalf("Board list watch error: %s\n", err) } - if res.EventType == "error" { - log.Printf("res: %s\n", res.Error) + if res.GetEventType() == "error" { + log.Printf("res: %s\n", res.GetError()) continue } - log.Printf("event: %s, address: %s\n", res.EventType, res.Port.Port.Address) - if res.EventType == "add" { - log.Printf("protocol: %s, ", res.Port.Port.Protocol) - log.Printf("protocolLabel: %s, ", res.Port.Port.ProtocolLabel) - log.Printf("boards: %s\n\n", res.Port.MatchingBoards) + log.Printf("event: %s, address: %s\n", res.GetEventType(), res.GetPort().GetPort().GetAddress()) + if res.GetEventType() == "add" { + log.Printf("protocol: %s, ", res.GetPort().GetPort().GetProtocol()) + log.Printf("protocolLabel: %s, ", res.GetPort().GetPort().GetProtocolLabel()) + log.Printf("boards: %s\n\n", res.GetPort().GetMatchingBoards()) } } }() diff --git a/commands/board/details.go b/commands/board/details.go index c00f315c788..90fabcae49d 100644 --- a/commands/board/details.go +++ b/commands/board/details.go @@ -52,16 +52,16 @@ func Details(ctx context.Context, req *rpc.BoardDetailsRequest) (*rpc.BoardDetai details.Version = board.PlatformRelease.Version.String() details.IdentificationProperties = []*rpc.BoardIdentificationProperties{} for _, p := range board.GetIdentificationProperties() { - details.IdentificationProperties = append(details.IdentificationProperties, &rpc.BoardIdentificationProperties{ + details.IdentificationProperties = append(details.GetIdentificationProperties(), &rpc.BoardIdentificationProperties{ Properties: p.AsMap(), }) } for _, k := range boardProperties.Keys() { v := boardProperties.Get(k) - details.BuildProperties = append(details.BuildProperties, k+"="+v) + details.BuildProperties = append(details.GetBuildProperties(), k+"="+v) } if !req.GetDoNotExpandBuildProperties() { - details.BuildProperties, _ = utils.ExpandBuildProperties(details.BuildProperties) + details.BuildProperties, _ = utils.ExpandBuildProperties(details.GetBuildProperties()) } details.DebuggingSupported = boardProperties.ContainsKey("debug.executable") || @@ -111,10 +111,10 @@ func Details(ctx context.Context, req *rpc.BoardDetailsRequest) (*rpc.BoardDetai } configValue.Value = value configValue.ValueLabel = values.Get(value) - configOption.Values = append(configOption.Values, configValue) + configOption.Values = append(configOption.GetValues(), configValue) } - details.ConfigOptions = append(details.ConfigOptions, configOption) + details.ConfigOptions = append(details.GetConfigOptions(), configOption) } details.ToolsDependencies = []*rpc.ToolsDependencies{} @@ -132,7 +132,7 @@ func Details(ctx context.Context, req *rpc.BoardDetailsRequest) (*rpc.BoardDetai }) } } - details.ToolsDependencies = append(details.ToolsDependencies, &rpc.ToolsDependencies{ + details.ToolsDependencies = append(details.GetToolsDependencies(), &rpc.ToolsDependencies{ Name: tool.ToolName, Packager: tool.ToolPackager, Version: tool.ToolVersion.String(), @@ -142,7 +142,7 @@ func Details(ctx context.Context, req *rpc.BoardDetailsRequest) (*rpc.BoardDetai details.Programmers = []*rpc.Programmer{} for id, p := range boardPlatformRelease.Programmers { - details.Programmers = append(details.Programmers, &rpc.Programmer{ + details.Programmers = append(details.GetProgrammers(), &rpc.Programmer{ Platform: boardPlatformRelease.Name, Id: id, Name: p.Name, diff --git a/commands/board/list.go b/commands/board/list.go index b953efb25d5..1f39928cb2f 100644 --- a/commands/board/list.go +++ b/commands/board/list.go @@ -182,12 +182,12 @@ func identify(pme *packagemanager.Explorer, port *discovery.Port) ([]*rpc.BoardL // Sort by FQBN alphabetically sort.Slice(boards, func(i, j int) bool { - return strings.ToLower(boards[i].Fqbn) < strings.ToLower(boards[j].Fqbn) + return strings.ToLower(boards[i].GetFqbn()) < strings.ToLower(boards[j].GetFqbn()) }) // Put Arduino boards before others in case there are non Arduino boards with identical VID:PID combination sort.SliceStable(boards, func(i, j int) bool { - if boards[i].Platform.Metadata.Maintainer == "Arduino" && boards[j].Platform.Metadata.Maintainer != "Arduino" { + if boards[i].GetPlatform().GetMetadata().GetMaintainer() == "Arduino" && boards[j].GetPlatform().GetMetadata().GetMaintainer() != "Arduino" { return true } return false @@ -246,8 +246,8 @@ func List(req *rpc.BoardListRequest) (r []*rpc.DetectedPort, discoveryStartError } func hasMatchingBoard(b *rpc.DetectedPort, fqbnFilter *cores.FQBN) bool { - for _, detectedBoard := range b.MatchingBoards { - detectedFqbn, err := cores.ParseFQBN(detectedBoard.Fqbn) + for _, detectedBoard := range b.GetMatchingBoards() { + detectedFqbn, err := cores.ParseFQBN(detectedBoard.GetFqbn()) if err != nil { continue } diff --git a/commands/board/list_test.go b/commands/board/list_test.go index 0f92e4c3896..aaf6b3bec5e 100644 --- a/commands/board/list_test.go +++ b/commands/board/list_test.go @@ -54,8 +54,8 @@ func TestGetByVidPid(t *testing.T) { res, err := apiByVidPid("0xf420", "0XF069") require.Nil(t, err) require.Len(t, res, 1) - require.Equal(t, "Arduino/Genuino MKR1000", res[0].Name) - require.Equal(t, "arduino:samd:mkr1000", res[0].Fqbn) + require.Equal(t, "Arduino/Genuino MKR1000", res[0].GetName()) + require.Equal(t, "arduino:samd:mkr1000", res[0].GetFqbn()) // wrong vid (too long), wrong pid (not an hex value) _, err = apiByVidPid("0xfffff", "0xDEFG") @@ -156,8 +156,8 @@ func TestBoardIdentifySorting(t *testing.T) { require.Len(t, res, 4) // Verify expected sorting - require.Equal(t, res[0].Fqbn, "arduino:avr:assurdo") - require.Equal(t, res[1].Fqbn, "arduino:avr:nessuno") - require.Equal(t, res[2].Fqbn, "packager:platform:boardA") - require.Equal(t, res[3].Fqbn, "packager:platform:boardB") + require.Equal(t, res[0].GetFqbn(), "arduino:avr:assurdo") + require.Equal(t, res[1].GetFqbn(), "arduino:avr:nessuno") + require.Equal(t, res[2].GetFqbn(), "packager:platform:boardA") + require.Equal(t, res[3].GetFqbn(), "packager:platform:boardB") } diff --git a/commands/board/listall.go b/commands/board/listall.go index 407b54ad8e7..430f06cee77 100644 --- a/commands/board/listall.go +++ b/commands/board/listall.go @@ -71,7 +71,7 @@ func ListAll(ctx context.Context, req *rpc.BoardListAllRequest) (*rpc.BoardListA continue } - list.Boards = append(list.Boards, &rpc.BoardListItem{ + list.Boards = append(list.GetBoards(), &rpc.BoardListItem{ Name: board.Name(), Fqbn: board.FQBN(), IsHidden: board.IsHidden(), diff --git a/commands/board/search.go b/commands/board/search.go index bd8702504d7..bda9fd6cf64 100644 --- a/commands/board/search.go +++ b/commands/board/search.go @@ -94,10 +94,10 @@ func Search(ctx context.Context, req *rpc.BoardSearchRequest) (*rpc.BoardSearchR } sort.Slice(foundBoards, func(i, j int) bool { - if foundBoards[i].Name != foundBoards[j].Name { - return foundBoards[i].Name < foundBoards[j].Name + if foundBoards[i].GetName() != foundBoards[j].GetName() { + return foundBoards[i].GetName() < foundBoards[j].GetName() } - return foundBoards[i].Platform.Metadata.Id < foundBoards[j].Platform.Metadata.Id + return foundBoards[i].GetPlatform().GetMetadata().GetId() < foundBoards[j].GetPlatform().GetMetadata().GetId() }) return &rpc.BoardSearchResponse{Boards: foundBoards}, nil diff --git a/commands/compile/compile.go b/commands/compile/compile.go index c168f27998a..3a28709496f 100644 --- a/commands/compile/compile.go +++ b/commands/compile/compile.go @@ -54,7 +54,7 @@ func Compile(ctx context.Context, req *rpc.CompileRequest, outStream, errStream // the optionality of this property, otherwise we would have no way of knowing if the property // was set in the request or it's just the default boolean value. if reqExportBinaries := req.GetExportBinaries(); reqExportBinaries != nil { - exportBinaries = reqExportBinaries.Value + exportBinaries = reqExportBinaries.GetValue() } pme, release := instances.GetPackageManagerExplorer(req.GetInstance()) @@ -110,13 +110,13 @@ func Compile(ctx context.Context, req *rpc.CompileRequest, outStream, errStream r.BuildPlatform = buildPlatform.ToRPCPlatformReference() // Setup sign keys if requested - if req.KeysKeychain != "" { + if req.GetKeysKeychain() != "" { boardBuildProperties.Set("build.keys.keychain", req.GetKeysKeychain()) } - if req.SignKey != "" { + if req.GetSignKey() != "" { boardBuildProperties.Set("build.keys.sign_key", req.GetSignKey()) } - if req.EncryptKey != "" { + if req.GetEncryptKey() != "" { boardBuildProperties.Set("build.keys.encrypt_key", req.GetEncryptKey()) } // At the current time we do not have a way of knowing if a board supports the secure boot or not, @@ -197,7 +197,7 @@ func Compile(ctx context.Context, req *rpc.CompileRequest, outStream, errStream targetPlatform, actualPlatform, req.GetSkipLibrariesDiscovery(), libsManager, - paths.NewPathList(req.Library...), + paths.NewPathList(req.GetLibrary()...), outStream, errStream, req.GetVerbose(), req.GetWarnings(), progressCB, ) @@ -231,10 +231,10 @@ func Compile(ctx context.Context, req *rpc.CompileRequest, outStream, errStream keys := buildProperties.Keys() sort.Strings(keys) for _, key := range keys { - r.BuildProperties = append(r.BuildProperties, key+"="+buildProperties.Get(key)) + r.BuildProperties = append(r.GetBuildProperties(), key+"="+buildProperties.Get(key)) } if !req.GetDoNotExpandBuildProperties() { - r.BuildProperties, _ = utils.ExpandBuildProperties(r.BuildProperties) + r.BuildProperties, _ = utils.ExpandBuildProperties(r.GetBuildProperties()) } }() diff --git a/commands/core/download.go b/commands/core/download.go index 78d7539d9da..2edfc532705 100644 --- a/commands/core/download.go +++ b/commands/core/download.go @@ -42,8 +42,8 @@ func PlatformDownload(ctx context.Context, req *rpc.PlatformDownloadRequest, dow } ref := &packagemanager.PlatformReference{ - Package: req.PlatformPackage, - PlatformArchitecture: req.Architecture, + Package: req.GetPlatformPackage(), + PlatformArchitecture: req.GetArchitecture(), PlatformVersion: version, } platform, tools, err := pme.FindPlatformReleaseDependencies(ref) diff --git a/commands/core/install.go b/commands/core/install.go index 6a159f7de50..3aa6043bab6 100644 --- a/commands/core/install.go +++ b/commands/core/install.go @@ -41,8 +41,8 @@ func PlatformInstall(ctx context.Context, req *rpc.PlatformInstallRequest, downl } ref := &packagemanager.PlatformReference{ - Package: req.PlatformPackage, - PlatformArchitecture: req.Architecture, + Package: req.GetPlatformPackage(), + PlatformArchitecture: req.GetArchitecture(), PlatformVersion: version, } platformRelease, tools, err := pme.FindPlatformReleaseDependencies(ref) @@ -74,7 +74,7 @@ func PlatformInstall(ctx context.Context, req *rpc.PlatformInstallRequest, downl if err := install(); err != nil { return nil, err } - if err := commands.Init(&rpc.InitRequest{Instance: req.Instance}, nil); err != nil { + if err := commands.Init(&rpc.InitRequest{Instance: req.GetInstance()}, nil); err != nil { return nil, err } return &rpc.PlatformInstallResponse{}, nil diff --git a/commands/core/search.go b/commands/core/search.go index c0341b40a91..1cde667090f 100644 --- a/commands/core/search.go +++ b/commands/core/search.go @@ -37,11 +37,11 @@ func PlatformSearch(req *rpc.PlatformSearchRequest) (*rpc.PlatformSearchResponse defer release() res := []*cores.Platform{} - if isUsb, _ := regexp.MatchString("[0-9a-f]{4}:[0-9a-f]{4}", req.SearchArgs); isUsb { - vid, pid := req.SearchArgs[:4], req.SearchArgs[5:] + if isUsb, _ := regexp.MatchString("[0-9a-f]{4}:[0-9a-f]{4}", req.GetSearchArgs()); isUsb { + vid, pid := req.GetSearchArgs()[:4], req.GetSearchArgs()[5:] res = pme.FindPlatformReleaseProvidingBoardsWithVidPid(vid, pid) } else { - searchArgs := utils.SearchTermsFromQueryString(req.SearchArgs) + searchArgs := utils.SearchTermsFromQueryString(req.GetSearchArgs()) for _, targetPackage := range pme.GetPackages() { for _, platform := range targetPackage.Platforms { if platform == nil { @@ -49,7 +49,7 @@ func PlatformSearch(req *rpc.PlatformSearchRequest) (*rpc.PlatformSearchResponse } // Users can install platforms manually in the Sketchbook hardware folder, // if not explictily requested we skip them. - if !req.ManuallyInstalled && platform.ManuallyInstalled { + if !req.GetManuallyInstalled() && platform.ManuallyInstalled { continue } @@ -94,7 +94,7 @@ func PlatformSearch(req *rpc.PlatformSearchRequest) (*rpc.PlatformSearchResponse } for _, platformRelease := range platform.GetAllReleases() { rpcPlatformRelease := commands.PlatformReleaseToRPC(platformRelease) - rpcPlatformSummary.Releases[rpcPlatformRelease.Version] = rpcPlatformRelease + rpcPlatformSummary.Releases[rpcPlatformRelease.GetVersion()] = rpcPlatformRelease } out = append(out, rpcPlatformSummary) } @@ -104,7 +104,7 @@ func PlatformSearch(req *rpc.PlatformSearchRequest) (*rpc.PlatformSearchResponse return strings.ToLower(out[i].GetMetadata().GetId()) < strings.ToLower(out[j].GetMetadata().GetId()) }) sort.SliceStable(out, func(i, j int) bool { - return !out[i].GetMetadata().Deprecated && out[j].GetMetadata().Deprecated + return !out[i].GetMetadata().GetDeprecated() && out[j].GetMetadata().GetDeprecated() }) return &rpc.PlatformSearchResponse{SearchOutput: out}, nil } diff --git a/commands/core/search_test.go b/commands/core/search_test.go index ea3fdc4ef9d..9234f92809e 100644 --- a/commands/core/search_test.go +++ b/commands/core/search_test.go @@ -49,8 +49,8 @@ func TestPlatformSearch(t *testing.T) { require.Nil(t, stat) require.NotNil(t, res) - require.Len(t, res.SearchOutput, 1) - require.Contains(t, res.SearchOutput, &rpc.PlatformSummary{ + require.Len(t, res.GetSearchOutput(), 1) + require.Contains(t, res.GetSearchOutput(), &rpc.PlatformSummary{ Metadata: &rpc.PlatformMetadata{ Id: "Retrokits-RK002:arm", Maintainer: "Retrokits (www.retrokits.com)", @@ -89,8 +89,8 @@ func TestPlatformSearch(t *testing.T) { }) require.Nil(t, stat) require.NotNil(t, res) - require.Len(t, res.SearchOutput, 1) - require.Contains(t, res.SearchOutput, &rpc.PlatformSummary{ + require.Len(t, res.GetSearchOutput(), 1) + require.Contains(t, res.GetSearchOutput(), &rpc.PlatformSummary{ Metadata: &rpc.PlatformMetadata{ Id: "Retrokits-RK002:arm", Maintainer: "Retrokits (www.retrokits.com)", @@ -129,8 +129,8 @@ func TestPlatformSearch(t *testing.T) { }) require.Nil(t, stat) require.NotNil(t, res) - require.Len(t, res.SearchOutput, 1) - require.Contains(t, res.SearchOutput, &rpc.PlatformSummary{ + require.Len(t, res.GetSearchOutput(), 1) + require.Contains(t, res.GetSearchOutput(), &rpc.PlatformSummary{ Metadata: &rpc.PlatformMetadata{ Id: "Retrokits-RK002:arm", Maintainer: "Retrokits (www.retrokits.com)", @@ -169,8 +169,8 @@ func TestPlatformSearch(t *testing.T) { }) require.Nil(t, stat) require.NotNil(t, res) - require.Len(t, res.SearchOutput, 1) - require.Contains(t, res.SearchOutput, &rpc.PlatformSummary{ + require.Len(t, res.GetSearchOutput(), 1) + require.Contains(t, res.GetSearchOutput(), &rpc.PlatformSummary{ Metadata: &rpc.PlatformMetadata{ Id: "Retrokits-RK002:arm", Maintainer: "Retrokits (www.retrokits.com)", @@ -209,8 +209,8 @@ func TestPlatformSearch(t *testing.T) { }) require.Nil(t, stat) require.NotNil(t, res) - require.Len(t, res.SearchOutput, 1) - require.Contains(t, res.SearchOutput, &rpc.PlatformSummary{ + require.Len(t, res.GetSearchOutput(), 1) + require.Contains(t, res.GetSearchOutput(), &rpc.PlatformSummary{ Metadata: &rpc.PlatformMetadata{ Id: "arduino:avr", Maintainer: "Arduino", @@ -267,8 +267,8 @@ func TestPlatformSearch(t *testing.T) { }) require.Nil(t, stat) require.NotNil(t, res) - require.Len(t, res.SearchOutput, 1) - require.Contains(t, res.SearchOutput, &rpc.PlatformSummary{ + require.Len(t, res.GetSearchOutput(), 1) + require.Contains(t, res.GetSearchOutput(), &rpc.PlatformSummary{ Metadata: &rpc.PlatformMetadata{ Id: "arduino:avr", Indexed: true, @@ -342,11 +342,11 @@ func TestPlatformSearchSorting(t *testing.T) { require.Nil(t, stat) require.NotNil(t, res) - require.Len(t, res.SearchOutput, 3) - require.Equal(t, res.SearchOutput[0].GetSortedReleases()[0].Name, "Arduino AVR Boards") - require.Equal(t, res.SearchOutput[0].Metadata.Deprecated, false) - require.Equal(t, res.SearchOutput[1].GetSortedReleases()[0].Name, "RK002") - require.Equal(t, res.SearchOutput[1].Metadata.Deprecated, false) - require.Equal(t, res.SearchOutput[2].GetLatestRelease().Name, "Platform") - require.Equal(t, res.SearchOutput[2].Metadata.Deprecated, true) + require.Len(t, res.GetSearchOutput(), 3) + require.Equal(t, res.GetSearchOutput()[0].GetSortedReleases()[0].GetName(), "Arduino AVR Boards") + require.Equal(t, res.GetSearchOutput()[0].GetMetadata().GetDeprecated(), false) + require.Equal(t, res.GetSearchOutput()[1].GetSortedReleases()[0].GetName(), "RK002") + require.Equal(t, res.GetSearchOutput()[1].GetMetadata().GetDeprecated(), false) + require.Equal(t, res.GetSearchOutput()[2].GetLatestRelease().GetName(), "Platform") + require.Equal(t, res.GetSearchOutput()[2].GetMetadata().GetDeprecated(), true) } diff --git a/commands/core/uninstall.go b/commands/core/uninstall.go index ec0ae20bc08..6038b8fd89b 100644 --- a/commands/core/uninstall.go +++ b/commands/core/uninstall.go @@ -30,7 +30,7 @@ func PlatformUninstall(ctx context.Context, req *rpc.PlatformUninstallRequest, t if err := platformUninstall(ctx, req, taskCB); err != nil { return nil, err } - if err := commands.Init(&rpc.InitRequest{Instance: req.Instance}, nil); err != nil { + if err := commands.Init(&rpc.InitRequest{Instance: req.GetInstance()}, nil); err != nil { return nil, err } return &rpc.PlatformUninstallResponse{}, nil @@ -45,8 +45,8 @@ func platformUninstall(ctx context.Context, req *rpc.PlatformUninstallRequest, t defer release() ref := &packagemanager.PlatformReference{ - Package: req.PlatformPackage, - PlatformArchitecture: req.Architecture, + Package: req.GetPlatformPackage(), + PlatformArchitecture: req.GetArchitecture(), } if ref.PlatformVersion == nil { platform := pme.FindPlatform(ref) diff --git a/commands/core/upgrade.go b/commands/core/upgrade.go index 19c93fe95cf..b27ca6cd8ae 100644 --- a/commands/core/upgrade.go +++ b/commands/core/upgrade.go @@ -37,8 +37,8 @@ func PlatformUpgrade(ctx context.Context, req *rpc.PlatformUpgradeRequest, downl // Extract all PlatformReference to platforms that have updates ref := &packagemanager.PlatformReference{ - Package: req.PlatformPackage, - PlatformArchitecture: req.Architecture, + Package: req.GetPlatformPackage(), + PlatformArchitecture: req.GetArchitecture(), } platform, err := pme.DownloadAndInstallPlatformUpgrades(ref, downloadCB, taskCB, req.GetSkipPostInstall(), req.GetSkipPreUninstall()) if err != nil { @@ -59,7 +59,7 @@ func PlatformUpgrade(ctx context.Context, req *rpc.PlatformUpgradeRequest, downl if err != nil { return &rpc.PlatformUpgradeResponse{Platform: rpcPlatform}, err } - if err := commands.Init(&rpc.InitRequest{Instance: req.Instance}, nil); err != nil { + if err := commands.Init(&rpc.InitRequest{Instance: req.GetInstance()}, nil); err != nil { return nil, err } diff --git a/commands/daemon/daemon.go b/commands/daemon/daemon.go index ef6e4daa506..64b2fc0010f 100644 --- a/commands/daemon/daemon.go +++ b/commands/daemon/daemon.go @@ -88,7 +88,7 @@ func (s *ArduinoCoreServerImpl) BoardSearch(ctx context.Context, req *rpc.BoardS // BoardListWatch FIXMEDOC func (s *ArduinoCoreServerImpl) BoardListWatch(req *rpc.BoardListWatchRequest, stream rpc.ArduinoCoreService_BoardListWatchServer) error { syncSend := NewSynchronizedSend(stream.Send) - if req.Instance == nil { + if req.GetInstance() == nil { err := fmt.Errorf(tr("no instance specified")) syncSend.Send(&rpc.BoardListWatchResponse{ EventType: "error", @@ -460,7 +460,7 @@ func (s *ArduinoCoreServerImpl) Monitor(stream rpc.ArduinoCoreService_MonitorSer } if conf := msg.GetPortConfiguration(); conf != nil { for _, c := range conf.GetSettings() { - if err := portProxy.Config(c.SettingId, c.Value); err != nil { + if err := portProxy.Config(c.GetSettingId(), c.GetValue()); err != nil { syncSend.Send(&rpc.MonitorResponse{Error: err.Error()}) } } diff --git a/commands/daemon/settings.go b/commands/daemon/settings.go index b5a03d34b49..0043c8859c0 100644 --- a/commands/daemon/settings.go +++ b/commands/daemon/settings.go @@ -134,7 +134,7 @@ func (s *ArduinoCoreServerImpl) SettingsSetValue(ctx context.Context, val *rpc.S // and that's picked up when the CLI is run as daemon, either using the default path or a custom one // set with the --config-file flag. func (s *ArduinoCoreServerImpl) SettingsWrite(ctx context.Context, req *rpc.SettingsWriteRequest) (*rpc.SettingsWriteResponse, error) { - if err := configuration.Settings.WriteConfigAs(req.FilePath); err != nil { + if err := configuration.Settings.WriteConfigAs(req.GetFilePath()); err != nil { return nil, err } return &rpc.SettingsWriteResponse{}, nil diff --git a/commands/daemon/term_example/main.go b/commands/daemon/term_example/main.go index 16aa36f3d53..faa86198a5f 100644 --- a/commands/daemon/term_example/main.go +++ b/commands/daemon/term_example/main.go @@ -44,7 +44,7 @@ func main() { if err != nil { log.Fatal("Create:", err) } - instance := resp.Instance + instance := resp.GetInstance() respStream, err := cli.Init(context.Background(), &commands.InitRequest{Instance: instance}) if err != nil { @@ -70,8 +70,8 @@ func main() { if len(ports) == 0 { log.Fatal("No port to connect!") } - port := ports[0].Port - fmt.Println("Detected port:", port.Label, port.ProtocolLabel) + port := ports[0].GetPort() + fmt.Println("Detected port:", port.GetLabel(), port.GetProtocolLabel()) connectToPort(cli, instance, port) time.Sleep(5 * time.Second) diff --git a/commands/debug/debug.go b/commands/debug/debug.go index ab55e317508..f3faaaacfaf 100644 --- a/commands/debug/debug.go +++ b/commands/debug/debug.go @@ -130,11 +130,11 @@ func getCommandLine(req *rpc.GetDebugConfigRequest, pme *packagemanager.Explorer var gdbPath *paths.Path switch debugInfo.GetToolchain() { case "gcc": - gdbexecutable := debugInfo.ToolchainPrefix + "gdb" + gdbexecutable := debugInfo.GetToolchainPrefix() + "gdb" if runtime.GOOS == "windows" { gdbexecutable += ".exe" } - gdbPath = paths.New(debugInfo.ToolchainPath).Join(gdbexecutable) + gdbPath = paths.New(debugInfo.GetToolchainPath()).Join(gdbexecutable) default: return nil, &arduino.FailedDebugError{Message: tr("Toolchain '%s' is not supported", debugInfo.GetToolchain())} } @@ -159,11 +159,11 @@ func getCommandLine(req *rpc.GetDebugConfigRequest, pme *packagemanager.Explorer switch debugInfo.GetServer() { case "openocd": var openocdConf rpc.DebugOpenOCDServerConfiguration - if err := debugInfo.ServerConfiguration.UnmarshalTo(&openocdConf); err != nil { + if err := debugInfo.GetServerConfiguration().UnmarshalTo(&openocdConf); err != nil { return nil, err } - serverCmd := fmt.Sprintf(`target extended-remote | "%s"`, debugInfo.ServerPath) + serverCmd := fmt.Sprintf(`target extended-remote | "%s"`, debugInfo.GetServerPath()) if cfg := openocdConf.GetScriptsDir(); cfg != "" { serverCmd += fmt.Sprintf(` -s "%s"`, cfg) @@ -184,7 +184,7 @@ func getCommandLine(req *rpc.GetDebugConfigRequest, pme *packagemanager.Explorer } // Add executable - add(debugInfo.Executable) + add(debugInfo.GetExecutable()) // Transform every path to forward slashes (on Windows some tools further // escapes the command line so the backslash "\" gets in the way). diff --git a/commands/debug/debug_info.go b/commands/debug/debug_info.go index 68727dc77bc..0a0598b7af5 100644 --- a/commands/debug/debug_info.go +++ b/commands/debug/debug_info.go @@ -138,8 +138,8 @@ func getDebugProperties(req *rpc.GetDebugConfigRequest, pme *packagemanager.Expl // Set debug port property port := req.GetPort() if port.GetAddress() != "" { - toolProperties.Set("debug.port", port.Address) - portFile := strings.TrimPrefix(port.Address, "/dev/") + toolProperties.Set("debug.port", port.GetAddress()) + portFile := strings.TrimPrefix(port.GetAddress(), "/dev/") toolProperties.Set("debug.port.file", portFile) } diff --git a/commands/lib/install.go b/commands/lib/install.go index d06102b57a6..2b2af6b19e8 100644 --- a/commands/lib/install.go +++ b/commands/lib/install.go @@ -40,31 +40,31 @@ func LibraryInstall(ctx context.Context, req *rpc.LibraryInstallRequest, downloa toInstall := map[string]*rpc.LibraryDependencyStatus{} installLocation := libraries.FromRPCLibraryInstallLocation(req.GetInstallLocation()) - if req.NoDeps { - toInstall[req.Name] = &rpc.LibraryDependencyStatus{ - Name: req.Name, - VersionRequired: req.Version, + if req.GetNoDeps() { + toInstall[req.GetName()] = &rpc.LibraryDependencyStatus{ + Name: req.GetName(), + VersionRequired: req.GetVersion(), } } else { res, err := LibraryResolveDependencies(ctx, &rpc.LibraryResolveDependenciesRequest{ - Instance: req.Instance, - Name: req.Name, - Version: req.Version, + Instance: req.GetInstance(), + Name: req.GetName(), + Version: req.GetVersion(), }) if err != nil { return err } - for _, dep := range res.Dependencies { - if existingDep, has := toInstall[dep.Name]; has { - if existingDep.VersionRequired != dep.VersionRequired { + for _, dep := range res.GetDependencies() { + if existingDep, has := toInstall[dep.GetName()]; has { + if existingDep.GetVersionRequired() != dep.GetVersionRequired() { err := errors.New( tr("two different versions of the library %[1]s are required: %[2]s and %[3]s", - dep.Name, dep.VersionRequired, existingDep.VersionRequired)) + dep.GetName(), dep.GetVersionRequired(), existingDep.GetVersionRequired())) return &arduino.LibraryDependenciesResolutionFailedError{Cause: err} } } - toInstall[dep.Name] = dep + toInstall[dep.GetName()] = dep } } @@ -72,8 +72,8 @@ func LibraryInstall(ctx context.Context, req *rpc.LibraryInstallRequest, downloa libReleasesToInstall := map[*librariesindex.Release]*librariesmanager.LibraryInstallPlan{} for _, lib := range toInstall { libRelease, err := findLibraryIndexRelease(lm, &rpc.LibraryInstallRequest{ - Name: lib.Name, - Version: lib.VersionRequired, + Name: lib.GetName(), + Version: lib.GetVersionRequired(), }) if err != nil { return err @@ -99,7 +99,7 @@ func LibraryInstall(ctx context.Context, req *rpc.LibraryInstallRequest, downloa for libRelease, installTask := range libReleasesToInstall { // Checks if libRelease is the requested library and not a dependency downloadReason := "depends" - if libRelease.GetName() == req.Name { + if libRelease.GetName() == req.GetName() { downloadReason = "install" if installTask.ReplacedLib != nil { downloadReason = "upgrade" @@ -116,7 +116,7 @@ func LibraryInstall(ctx context.Context, req *rpc.LibraryInstallRequest, downloa } } - if err := commands.Init(&rpc.InitRequest{Instance: req.Instance}, nil); err != nil { + if err := commands.Init(&rpc.InitRequest{Instance: req.GetInstance()}, nil); err != nil { return err } @@ -145,7 +145,7 @@ func installLibrary(lm *librariesmanager.LibrariesManager, libRelease *libraries // ZipLibraryInstall FIXMEDOC func ZipLibraryInstall(ctx context.Context, req *rpc.ZipLibraryInstallRequest, taskCB rpc.TaskProgressCB) error { lm := instances.GetLibraryManager(req.GetInstance()) - if err := lm.InstallZipLib(ctx, paths.New(req.Path), req.Overwrite); err != nil { + if err := lm.InstallZipLib(ctx, paths.New(req.GetPath()), req.GetOverwrite()); err != nil { return &arduino.FailedLibraryInstallError{Cause: err} } taskCB(&rpc.TaskProgress{Message: tr("Library installed"), Completed: true}) @@ -155,7 +155,7 @@ func ZipLibraryInstall(ctx context.Context, req *rpc.ZipLibraryInstallRequest, t // GitLibraryInstall FIXMEDOC func GitLibraryInstall(ctx context.Context, req *rpc.GitLibraryInstallRequest, taskCB rpc.TaskProgressCB) error { lm := instances.GetLibraryManager(req.GetInstance()) - if err := lm.InstallGitLib(req.Url, req.Overwrite); err != nil { + if err := lm.InstallGitLib(req.GetUrl(), req.GetOverwrite()); err != nil { return &arduino.FailedLibraryInstallError{Cause: err} } taskCB(&rpc.TaskProgress{Message: tr("Library installed"), Completed: true}) diff --git a/commands/lib/resolve_deps.go b/commands/lib/resolve_deps.go index 1c26d026f97..d0babcf38ff 100644 --- a/commands/lib/resolve_deps.go +++ b/commands/lib/resolve_deps.go @@ -76,7 +76,7 @@ func LibraryResolveDependencies(ctx context.Context, req *rpc.LibraryResolveDepe }) } sort.Slice(res, func(i, j int) bool { - return res[i].Name < res[j].Name + return res[i].GetName() < res[j].GetName() }) return &rpc.LibraryResolveDependenciesResponse{Dependencies: res}, nil } diff --git a/commands/lib/search.go b/commands/lib/search.go index c9a9182a30c..c4a2afe8fd2 100644 --- a/commands/lib/search.go +++ b/commands/lib/search.go @@ -51,14 +51,14 @@ func searchLibrary(req *rpc.LibrarySearchRequest, lm *librariesmanager.Libraries // get a sorted slice of results sort.Slice(res, func(i, j int) bool { // Sort by name, but bubble up exact matches - equalsI := strings.EqualFold(res[i].Name, query) - equalsJ := strings.EqualFold(res[j].Name, query) + equalsI := strings.EqualFold(res[i].GetName(), query) + equalsJ := strings.EqualFold(res[j].GetName(), query) if equalsI && !equalsJ { return true } else if !equalsI && equalsJ { return false } - return res[i].Name < res[j].Name + return res[i].GetName() < res[j].GetName() }) return &rpc.LibrarySearchResponse{Libraries: res, Status: rpc.LibrarySearchStatus_LIBRARY_SEARCH_STATUS_SUCCESS} diff --git a/commands/lib/search_test.go b/commands/lib/search_test.go index 8a5870338cd..749c88722b0 100644 --- a/commands/lib/search_test.go +++ b/commands/lib/search_test.go @@ -38,8 +38,8 @@ func TestSearchLibrary(t *testing.T) { assert := assert.New(t) assert.Equal(resp.GetStatus(), rpc.LibrarySearchStatus_LIBRARY_SEARCH_STATUS_SUCCESS) assert.Equal(len(resp.GetLibraries()), 2) - assert.True(strings.Contains(resp.GetLibraries()[0].Name, "Test")) - assert.True(strings.Contains(resp.GetLibraries()[1].Name, "Test")) + assert.True(strings.Contains(resp.GetLibraries()[0].GetName(), "Test")) + assert.True(strings.Contains(resp.GetLibraries()[1].GetName(), "Test")) } func TestSearchLibrarySimilar(t *testing.T) { @@ -52,7 +52,7 @@ func TestSearchLibrarySimilar(t *testing.T) { assert.Equal(len(resp.GetLibraries()), 2) libs := map[string]*rpc.SearchedLibrary{} for _, l := range resp.GetLibraries() { - libs[l.Name] = l + libs[l.GetName()] = l } assert.Contains(libs, "ArduinoTestPackage") assert.Contains(libs, "Arduino") @@ -64,8 +64,8 @@ func TestSearchLibraryFields(t *testing.T) { query := func(q string) []string { libs := []string{} - for _, lib := range searchLibrary(&rpc.LibrarySearchRequest{SearchArgs: q}, lm).Libraries { - libs = append(libs, lib.Name) + for _, lib := range searchLibrary(&rpc.LibrarySearchRequest{SearchArgs: q},lm).GetLibraries()s { + libs = append(libs, lib.GetName()) } return libs } @@ -102,8 +102,8 @@ func TestSearchLibraryWithQualifiers(t *testing.T) { query := func(q string) []string { libs := []string{} - for _, lib := range searchLibrary(&rpc.LibrarySearchRequest{SearchArgs: q}, lm).Libraries { - libs = append(libs, lib.Name) + for _, lib := range searchLibrary(&rpc.LibrarySearchRequest{SearchArgs: q},lm).GetLibraries()s { + libs = append(libs, lib.GetName()) } return libs } diff --git a/commands/lib/uninstall.go b/commands/lib/uninstall.go index 63b54ba064e..57c56e95a5a 100644 --- a/commands/lib/uninstall.go +++ b/commands/lib/uninstall.go @@ -36,7 +36,7 @@ func LibraryUninstall(ctx context.Context, req *rpc.LibraryUninstallRequest, tas libs := lm.FindByReference(ref, libraries.User) if len(libs) == 0 { - taskCB(&rpc.TaskProgress{Message: tr("Library %s is not installed", req.Name), Completed: true}) + taskCB(&rpc.TaskProgress{Message: tr("Library %s is not installed", req.GetName()), Completed: true}) return nil } diff --git a/commands/lib/upgrade.go b/commands/lib/upgrade.go index fe7e938a040..6fb6f9add2b 100644 --- a/commands/lib/upgrade.go +++ b/commands/lib/upgrade.go @@ -31,7 +31,7 @@ func LibraryUpgradeAll(req *rpc.LibraryUpgradeAllRequest, downloadCB rpc.Downloa return &arduino.InvalidInstanceError{} } - if err := upgrade(req.Instance, listLibraries(lm, true, false), downloadCB, taskCB); err != nil { + if err := upgrade(req.GetInstance(), listLibraries(lm, true, false), downloadCB, taskCB); err != nil { return err } @@ -62,7 +62,7 @@ func LibraryUpgrade(ctx context.Context, req *rpc.LibraryUpgradeRequest, downloa } // Install update - return upgrade(req.Instance, []*installedLib{lib}, downloadCB, taskCB) + return upgrade(req.GetInstance(), []*installedLib{lib}, downloadCB, taskCB) } func upgrade(instance *rpc.Instance, libs []*installedLib, downloadCB rpc.DownloadProgressCB, taskCB rpc.TaskProgressCB) error { diff --git a/commands/monitor/monitor.go b/commands/monitor/monitor.go index 4da0c902868..285841f8374 100644 --- a/commands/monitor/monitor.go +++ b/commands/monitor/monitor.go @@ -84,10 +84,10 @@ func Monitor(ctx context.Context, req *rpc.MonitorRequest) (*PortProxy, *pluggab // Apply user-requested settings if portConfig := req.GetPortConfiguration(); portConfig != nil { - for _, setting := range portConfig.Settings { - boardSettings.Remove(setting.SettingId) // Remove board settings overridden by the user - if err := m.Configure(setting.SettingId, setting.Value); err != nil { - logrus.Errorf("Could not set configuration %s=%s: %s", setting.SettingId, setting.Value, err) + for _, setting := range portConfig.GetSettings() { + boardSettings.Remove(setting.GetSettingId()) // Remove board settings overridden by the user + if err := m.Configure(setting.GetSettingId(), setting.GetValue()); err != nil { + logrus.Errorf("Could not set configuration %s=%s: %s", setting.GetSettingId(), setting.GetValue(), err) } } } diff --git a/commands/sketch/archive.go b/commands/sketch/archive.go index 583ead6225a..059ab18bd35 100644 --- a/commands/sketch/archive.go +++ b/commands/sketch/archive.go @@ -36,7 +36,7 @@ func ArchiveSketch(ctx context.Context, req *rpc.ArchiveSketchRequest) (*rpc.Arc // sketchName is the name of the sketch without extension, for example "MySketch" var sketchName string - sketchPath := paths.New(req.SketchPath) + sketchPath := paths.New(req.GetSketchPath()) if sketchPath == nil { sketchPath = paths.New(".") } @@ -49,7 +49,7 @@ func ArchiveSketch(ctx context.Context, req *rpc.ArchiveSketchRequest) (*rpc.Arc sketchPath = s.FullPath sketchName = s.Name - archivePath := paths.New(req.ArchivePath) + archivePath := paths.New(req.GetArchivePath()) if archivePath == nil { archivePath = sketchPath.Parent() } @@ -66,7 +66,7 @@ func ArchiveSketch(ctx context.Context, req *rpc.ArchiveSketchRequest) (*rpc.Arc archivePath = paths.New(archivePath.String() + ".zip") } - if !req.Overwrite { + if !req.GetOverwrite() { if archivePath.Exist() { return nil, &arduino.InvalidArgumentError{Message: tr("Archive already exists")} } @@ -89,7 +89,7 @@ func ArchiveSketch(ctx context.Context, req *rpc.ArchiveSketchRequest) (*rpc.Arc for _, f := range filesToZip { - if !req.IncludeBuildDir { + if !req.GetIncludeBuildDir() { filePath, err := sketchPath.Parent().RelTo(f) if err != nil { return nil, &arduino.PermissionDeniedError{Message: tr("Error calculating relative file path"), Cause: err} diff --git a/commands/sketch/load.go b/commands/sketch/load.go index ee6eb649ca5..bd6b80e4a61 100644 --- a/commands/sketch/load.go +++ b/commands/sketch/load.go @@ -27,7 +27,7 @@ import ( // LoadSketch collects and returns all files composing a sketch func LoadSketch(ctx context.Context, req *rpc.LoadSketchRequest) (*rpc.LoadSketchResponse, error) { // TODO: This should be a ToRpc function for the Sketch struct - sk, err := sketch.New(paths.New(req.SketchPath)) + sk, err := sketch.New(paths.New(req.GetSketchPath())) if err != nil { return nil, &arduino.CantOpenSketchError{Cause: err} } diff --git a/commands/sketch/new.go b/commands/sketch/new.go index b4fe3ab0e82..e73f90a996a 100644 --- a/commands/sketch/new.go +++ b/commands/sketch/new.go @@ -45,23 +45,23 @@ var invalidNames = []string{"CON", "PRN", "AUX", "NUL", "COM0", "COM1", "COM2", // NewSketch creates a new sketch via gRPC func NewSketch(ctx context.Context, req *rpc.NewSketchRequest) (*rpc.NewSketchResponse, error) { var sketchesDir string - if len(req.SketchDir) > 0 { - sketchesDir = req.SketchDir + if len(req.GetSketchDir()) > 0 { + sketchesDir = req.GetSketchDir() } else { sketchesDir = configuration.Settings.GetString("directories.User") } - if err := validateSketchName(req.SketchName); err != nil { + if err := validateSketchName(req.GetSketchName()); err != nil { return nil, err } - sketchDirPath := paths.New(sketchesDir).Join(req.SketchName) + sketchDirPath := paths.New(sketchesDir).Join(req.GetSketchName()) if err := sketchDirPath.MkdirAll(); err != nil { return nil, &arduino.CantCreateSketchError{Cause: err} } sketchName := sketchDirPath.Base() sketchMainFilePath := sketchDirPath.Join(sketchName + globals.MainFileValidExtension) - if !req.Overwrite { + if !req.GetOverwrite() { if sketchMainFilePath.Exist() { return nil, &arduino.CantCreateSketchError{Cause: errors.New(tr(".ino file already exists"))} } diff --git a/commands/sketch/set_defaults.go b/commands/sketch/set_defaults.go index 1a4ebc6b752..17ac01dae34 100644 --- a/commands/sketch/set_defaults.go +++ b/commands/sketch/set_defaults.go @@ -27,7 +27,7 @@ import ( // SetSketchDefaults updates the sketch project file (sketch.yaml) with the given defaults // for the values `default_fqbn`, `default_port`, and `default_protocol`. func SetSketchDefaults(ctx context.Context, req *rpc.SetSketchDefaultsRequest) (*rpc.SetSketchDefaultsResponse, error) { - sk, err := sketch.New(paths.New(req.SketchPath)) + sk, err := sketch.New(paths.New(req.GetSketchPath())) if err != nil { return nil, &arduino.CantOpenSketchError{Cause: err} } diff --git a/commands/upload/upload.go b/commands/upload/upload.go index 56815f983a6..c7ea52c48e0 100644 --- a/commands/upload/upload.go +++ b/commands/upload/upload.go @@ -46,7 +46,7 @@ var tr = i18n.Tr // SupportedUserFields returns a SupportedUserFieldsResponse containing all the UserFields supported // by the upload tools needed by the board using the protocol specified in SupportedUserFieldsRequest. func SupportedUserFields(ctx context.Context, req *rpc.SupportedUserFieldsRequest) (*rpc.SupportedUserFieldsResponse, error) { - if req.Protocol == "" { + if req.GetProtocol() == "" { return nil, &arduino.MissingPortProtocolError{} } @@ -72,7 +72,7 @@ func SupportedUserFields(ctx context.Context, req *rpc.SupportedUserFieldsReques return nil, &arduino.UnknownFQBNError{Cause: err} } - toolID, err := getToolID(boardProperties, "upload", req.Protocol) + toolID, err := getToolID(boardProperties, "upload", req.GetProtocol()) if err != nil { return nil, err } diff --git a/commands/upload/upload_test.go b/commands/upload/upload_test.go index e1f87cd9832..d73ab6b315b 100644 --- a/commands/upload/upload_test.go +++ b/commands/upload/upload_test.go @@ -288,14 +288,14 @@ tools.arduino_ota.upload.field.password.secret=true`)) userFields := getUserFields("avrdude", platformRelease) require.Len(t, userFields, 2) - require.Equal(t, userFields[0].ToolId, "avrdude") - require.Equal(t, userFields[0].Name, "username") - require.Equal(t, userFields[0].Label, "Username") - require.False(t, userFields[0].Secret) - require.Equal(t, userFields[1].ToolId, "avrdude") - require.Equal(t, userFields[1].Name, "password") - require.Equal(t, userFields[1].Label, "Password") - require.True(t, userFields[1].Secret) + require.Equal(t, userFields[0].GetToolId(), "avrdude") + require.Equal(t, userFields[0].GetName(), "username") + require.Equal(t, userFields[0].GetLabel(), "Username") + require.False(t, userFields[0].GetSecret()) + require.Equal(t, userFields[1].GetToolId(), "avrdude") + require.Equal(t, userFields[1].GetName(), "password") + require.Equal(t, userFields[1].GetLabel(), "Password") + require.True(t, userFields[1].GetSecret()) props, err = properties.LoadFromBytes([]byte(` tools.arduino_ota.upload.field.password=Password @@ -310,10 +310,10 @@ tools.arduino_ota.upload.field.some_field=This is a really long label that ideal platformRelease.Properties = props userFields = getUserFields("arduino_ota", platformRelease) require.Len(t, userFields, 1) - require.Equal(t, userFields[0].ToolId, "arduino_ota") - require.Equal(t, userFields[0].Name, "some_field") - require.Equal(t, userFields[0].Label, "This is a really long label that ideally must nev…") - require.False(t, userFields[0].Secret) + require.Equal(t, userFields[0].GetToolId(), "arduino_ota") + require.Equal(t, userFields[0].GetName(), "some_field") + require.Equal(t, userFields[0].GetLabel(), "This is a really long label that ideally must nev…") + require.False(t, userFields[0].GetSecret()) } func TestOverrideProtocolProperties(t *testing.T) { diff --git a/internal/cli/arguments/completion.go b/internal/cli/arguments/completion.go index 89423edd1a7..4243a0fd409 100644 --- a/internal/cli/arguments/completion.go +++ b/internal/cli/arguments/completion.go @@ -39,8 +39,8 @@ func GetInstalledBoards() []string { }) var res []string // transform the data structure for the completion - for _, i := range list.Boards { - res = append(res, i.Fqbn+"\t"+i.Name) + for _, i := range list.GetBoards() { + res = append(res, i.GetFqbn()+"\t"+i.GetName()) } return res } @@ -59,10 +59,10 @@ func GetInstalledProgrammers() []string { list, _ := board.ListAll(context.Background(), listAllReq) installedProgrammers := make(map[string]string) - for _, board := range list.Boards { + for _, board := range list.GetBoards() { programmers, _ := upload.ListProgrammersAvailableForUpload(context.Background(), &rpc.ListProgrammersAvailableForUploadRequest{ Instance: inst, - Fqbn: board.Fqbn, + Fqbn: board.GetFqbn(), }) for _, programmer := range programmers.GetProgrammers() { installedProgrammers[programmer.GetId()] = programmer.GetName() @@ -91,7 +91,7 @@ func GetUninstallableCores() []string { var res []string // transform the data structure for the completion for _, i := range platforms.GetSearchOutput() { - if i.InstalledVersion == "" { + if i.GetInstalledVersion() == "" { continue } res = append(res, i.GetMetadata().GetId()+"\t"+i.GetInstalledRelease().GetName()) @@ -141,8 +141,8 @@ func getLibraries(all bool) []string { }) var res []string // transform the data structure for the completion - for _, i := range libs.InstalledLibraries { - res = append(res, i.Library.Name+"\t"+i.Library.Sentence) + for _, i := range libs.GetInstalledLibraries() { + res = append(res, i.GetLibrary().GetName()+"\t"+i.GetLibrary().GetSentence()) } return res } @@ -158,8 +158,8 @@ func GetInstallableLibs() []string { }) var res []string // transform the data structure for the completion - for _, i := range libs.Libraries { - res = append(res, i.Name+"\t"+i.Latest.Sentence) + for _, i := range libs.GetLibraries() { + res = append(res, i.GetName()+"\t"+i.GetLatest().GetSentence()) } return res } @@ -176,7 +176,7 @@ func GetAvailablePorts() []*rpc.Port { var res []*rpc.Port // transform the data structure for the completion for _, i := range list { - res = append(res, i.Port) + res = append(res, i.GetPort()) } return res } diff --git a/internal/cli/arguments/port.go b/internal/cli/arguments/port.go index 80df4b5c22c..de583dccf51 100644 --- a/internal/cli/arguments/port.go +++ b/internal/cli/arguments/port.go @@ -65,7 +65,7 @@ func (p *Port) GetPortAddressAndProtocol(instance *rpc.Instance, defaultAddress, if err != nil { return "", "", err } - return port.Address, port.Protocol, nil + return port.GetAddress(), port.GetProtocol(), nil } // GetPort returns the Port obtained by parsing command line arguments. @@ -145,13 +145,13 @@ func (p *Port) DetectFQBN(inst *rpc.Instance) (string, *rpc.Port) { if p.protocol != "" && p.protocol != port.GetProtocol() { continue } - if len(detectedPort.MatchingBoards) > 1 { + if len(detectedPort.GetMatchingBoards()) > 1 { feedback.FatalError(&arduino.MultipleBoardsDetectedError{Port: port}, feedback.ErrBadArgument) } - if len(detectedPort.MatchingBoards) == 0 { + if len(detectedPort.GetMatchingBoards()) == 0 { feedback.FatalError(&arduino.NoBoardsDetectedError{Port: port}, feedback.ErrBadArgument) } - return detectedPort.MatchingBoards[0].Fqbn, port + return detectedPort.GetMatchingBoards()[0].GetFqbn(), port } return "", nil } diff --git a/internal/cli/arguments/user_fields.go b/internal/cli/arguments/user_fields.go index 8f799d4c650..e9bf89c1ba4 100644 --- a/internal/cli/arguments/user_fields.go +++ b/internal/cli/arguments/user_fields.go @@ -25,11 +25,11 @@ import ( func AskForUserFields(userFields []*rpc.UserField) (map[string]string, error) { fields := map[string]string{} for _, f := range userFields { - value, err := feedback.InputUserField(f.Label, f.Secret) + value, err := feedback.InputUserField(f.GetLabel(), f.GetSecret()) if err != nil { return nil, err } - fields[f.Name] = value + fields[f.GetName()] = value } return fields, nil diff --git a/internal/cli/board/search.go b/internal/cli/board/search.go index 068dd0d0019..646cb3bbfb3 100644 --- a/internal/cli/board/search.go +++ b/internal/cli/board/search.go @@ -61,7 +61,7 @@ func runSearchCommand(cmd *cobra.Command, args []string) { feedback.Fatal(tr("Error searching boards: %v", err), feedback.ErrGeneric) } - feedback.PrintResult(searchResults{result.NewBoardListItems(res.Boards)}) + feedback.PrintResult(searchResults{result.NewBoardListItems(res.GetBoards())}) } // output from this command requires special formatting so we create a dedicated diff --git a/internal/cli/compile/compile.go b/internal/cli/compile/compile.go index 7cd66de7663..b6a2bafd060 100644 --- a/internal/cli/compile/compile.go +++ b/internal/cli/compile/compile.go @@ -252,16 +252,16 @@ func runCompileCommand(cmd *cobra.Command, args []string) { userFieldRes, err := upload.SupportedUserFields(context.Background(), &rpc.SupportedUserFieldsRequest{ Instance: inst, Fqbn: fqbn, - Protocol: port.Protocol, + Protocol: port.GetProtocol(), }) if err != nil { feedback.Fatal(tr("Error during Upload: %v", err), feedback.ErrGeneric) } fields := map[string]string{} - if len(userFieldRes.UserFields) > 0 { - feedback.Print(tr("Uploading to specified board using %s protocol requires the following info:", port.Protocol)) - if f, err := arguments.AskForUserFields(userFieldRes.UserFields); err != nil { + if len(userFieldRes.GetUserFields()) > 0 { + feedback.Print(tr("Uploading to specified board using %s protocol requires the following info:", port.GetProtocol())) + if f, err := arguments.AskForUserFields(userFieldRes.GetUserFields()); err != nil { feedback.FatalError(err, feedback.ErrBadArgument) } else { fields = f @@ -294,7 +294,7 @@ func runCompileCommand(cmd *cobra.Command, args []string) { libs := "" hasVendoredLibs := false for _, lib := range compileRes.GetUsedLibraries() { - if lib.Location != rpc.LibraryLocation_LIBRARY_LOCATION_USER && lib.Location != rpc.LibraryLocation_LIBRARY_LOCATION_UNMANAGED { + if lib.GetLocation() != rpc.LibraryLocation_LIBRARY_LOCATION_USER && lib.GetLocation() != rpc.LibraryLocation_LIBRARY_LOCATION_UNMANAGED { continue } if lib.GetVersion() == "" { @@ -325,8 +325,8 @@ func runCompileCommand(cmd *cobra.Command, args []string) { } if buildPlatform := compileRes.GetBuildPlatform(); buildPlatform != nil && - buildPlatform.Id != boardPlatform.Id && - buildPlatform.Version != boardPlatform.Version { + buildPlatform.GetId() != boardPlatform.GetId() && + buildPlatform.GetVersion() != boardPlatform.GetVersion() { profileOut += fmt.Sprintln(" - platform: " + buildPlatform.GetId() + " (" + buildPlatform.GetVersion() + ")") if url := buildPlatform.GetPackageUrl(); url != "" { profileOut += fmt.Sprintln(" platform_index_url: " + url) diff --git a/internal/cli/core/list.go b/internal/cli/core/list.go index 6ef5c14b451..c9b62a07553 100644 --- a/internal/cli/core/list.go +++ b/internal/cli/core/list.go @@ -75,10 +75,10 @@ func GetList(inst *rpc.Instance, all bool, updatableOnly bool) []*rpc.PlatformSu result := []*rpc.PlatformSummary{} for _, platform := range platforms.GetSearchOutput() { - if platform.InstalledVersion == "" && !platform.GetMetadata().ManuallyInstalled { + if platform.GetInstalledVersion() == "" && !platform.GetMetadata().GetManuallyInstalled() { continue } - if updatableOnly && platform.InstalledVersion == platform.LatestVersion { + if updatableOnly && platform.GetInstalledVersion() == platform.GetLatestVersion() { continue } result = append(result, platform) diff --git a/internal/cli/core/upgrade.go b/internal/cli/core/upgrade.go index 93bc6c0720f..c7282d9ba4d 100644 --- a/internal/cli/core/upgrade.go +++ b/internal/cli/core/upgrade.go @@ -69,12 +69,12 @@ func Upgrade(inst *rpc.Instance, args []string, skipPostInstall bool, skipPreUni targets := []*rpc.Platform{} for _, platform := range platforms.GetSearchOutput() { - if platform.InstalledVersion == "" { + if platform.GetInstalledVersion() == "" { continue } // if it's not updatable, skip it latestRelease := platform.GetLatestRelease() - if latestRelease != nil && platform.InstalledVersion != latestRelease.Version { + if latestRelease != nil && platform.GetInstalledVersion() != latestRelease.GetVersion() { targets = append(targets, &rpc.Platform{ Metadata: platform.GetMetadata(), Release: latestRelease, @@ -88,16 +88,16 @@ func Upgrade(inst *rpc.Instance, args []string, skipPostInstall bool, skipPreUni } for _, t := range targets { - args = append(args, t.GetMetadata().Id) + args = append(args, t.GetMetadata().GetId()) } } warningMissingIndex := func(response *rpc.PlatformUpgradeResponse) { - if response == nil || response.Platform == nil { + if response == nil || response.GetPlatform() == nil { return } - if !response.Platform.GetMetadata().Indexed { - feedback.Warning(tr("missing package index for %s, future updates cannot be guaranteed", response.Platform.GetMetadata().Id)) + if !response.GetPlatform().GetMetadata().GetIndexed() { + feedback.Warning(tr("missing package index for %s, future updates cannot be guaranteed", response.GetPlatform().GetMetadata().GetId())) } } diff --git a/internal/cli/debug/debug.go b/internal/cli/debug/debug.go index a4385c8e0d8..c5b72d2e841 100644 --- a/internal/cli/debug/debug.go +++ b/internal/cli/debug/debug.go @@ -138,16 +138,16 @@ type openOcdServerConfigResult struct { func newDebugInfoResult(info *rpc.GetDebugConfigResponse) *debugInfoResult { var toolchainConfig interface{} var serverConfig interface{} - switch info.Server { + switch info.GetServer() { case "openocd": var openocdConf rpc.DebugOpenOCDServerConfiguration if err := info.GetServerConfiguration().UnmarshalTo(&openocdConf); err != nil { feedback.Fatal(tr("Error during Debug: %v", err), feedback.ErrGeneric) } serverConfig = &openOcdServerConfigResult{ - Path: openocdConf.Path, - ScriptsDir: openocdConf.ScriptsDir, - Scripts: openocdConf.Scripts, + Path: openocdConf.GetPath(), + ScriptsDir: openocdConf.GetScriptsDir(), + Scripts: openocdConf.GetScripts(), } } customConfigs := map[string]any{} @@ -158,17 +158,17 @@ func newDebugInfoResult(info *rpc.GetDebugConfigResponse) *debugInfoResult { } } return &debugInfoResult{ - Executable: info.Executable, - Toolchain: info.Toolchain, - ToolchainPath: info.ToolchainPath, - ToolchainPrefix: info.ToolchainPrefix, + Executable: info.GetExecutable(), + Toolchain: info.GetToolchain(), + ToolchainPath: info.GetToolchainPath(), + ToolchainPrefix: info.GetToolchainPrefix(), ToolchainConfig: toolchainConfig, - Server: info.Server, - ServerPath: info.ServerPath, + Server: info.GetServer(), + ServerPath: info.GetServerPath(), ServerConfig: serverConfig, - SvdFile: info.SvdFile, + SvdFile: info.GetSvdFile(), CustomConfigs: customConfigs, - Programmer: info.Programmer, + Programmer: info.GetProgrammer(), } } diff --git a/internal/cli/feedback/result/rpc.go b/internal/cli/feedback/result/rpc.go index 63291754fe7..242d5d632f2 100644 --- a/internal/cli/feedback/result/rpc.go +++ b/internal/cli/feedback/result/rpc.go @@ -103,28 +103,28 @@ func NewPlatformRelease(in *rpc.PlatformRelease) *PlatformRelease { return nil } var boards []*Board - for _, board := range in.Boards { + for _, board := range in.GetBoards() { boards = append(boards, &Board{ - Name: board.Name, - Fqbn: board.Fqbn, + Name: board.GetName(), + Fqbn: board.GetFqbn(), }) } var help *HelpResource - if in.Help != nil { + if in.GetHelp() != nil { help = &HelpResource{ - Online: in.Help.Online, + Online: in.GetHelp().GetOnline(), } } res := &PlatformRelease{ - Name: in.Name, - Version: in.Version, - Type: in.Type, - Installed: in.Installed, + Name: in.GetName(), + Version: in.GetVersion(), + Type: in.GetType(), + Installed: in.GetInstalled(), Boards: boards, Help: help, - MissingMetadata: in.MissingMetadata, - Deprecated: in.Deprecated, - Compatible: in.Compatible, + MissingMetadata: in.GetMissingMetadata(), + Deprecated: in.GetDeprecated(), + Compatible: in.GetCompatible(), } return res } @@ -751,13 +751,13 @@ func NewPlatformMetadata(p *rpc.PlatformMetadata) *PlatformMetadata { return nil } return &PlatformMetadata{ - Id: p.Id, - Maintainer: p.Maintainer, - Website: p.Website, - Email: p.Email, - ManuallyInstalled: p.ManuallyInstalled, - Deprecated: p.Deprecated, - Indexed: p.Indexed, + Id: p.GetId(), + Maintainer: p.GetMaintainer(), + Website: p.GetWebsite(), + Email: p.GetEmail(), + ManuallyInstalled: p.GetManuallyInstalled(), + Deprecated: p.GetDeprecated(), + Indexed: p.GetIndexed(), } } @@ -987,9 +987,9 @@ func NewBoardListWatchResponse(r *rpc.BoardListWatchResponse) *BoardListWatchRes return nil } return &BoardListWatchResponse{ - EventType: r.EventType, - Port: NewDetectedPort(r.Port), - Error: r.Error, + EventType: r.GetEventType(), + Port: NewDetectedPort(r.GetPort()), + Error: r.GetError(), } } diff --git a/internal/cli/instance/instance.go b/internal/cli/instance/instance.go index 60fbe8b54f7..0cd9e8ceb85 100644 --- a/internal/cli/instance/instance.go +++ b/internal/cli/instance/instance.go @@ -52,7 +52,7 @@ func create() (*rpc.Instance, error) { if err != nil { return nil, err } - return res.Instance, nil + return res.GetInstance(), nil } // Init initializes instance by loading installed libraries and platforms. @@ -79,15 +79,15 @@ func InitWithProfile(instance *rpc.Instance, profileName string, sketchPath *pat var profile *rpc.Profile err := commands.Init(initReq, func(res *rpc.InitResponse) { if st := res.GetError(); st != nil { - feedback.Warning(tr("Error initializing instance: %v", st.Message)) + feedback.Warning(tr("Error initializing instance: %v", st.GetMessage())) } if progress := res.GetInitProgress(); progress != nil { - if progress.DownloadProgress != nil { - downloadCallback(progress.DownloadProgress) + if progress.GetDownloadProgress() != nil { + downloadCallback(progress.GetDownloadProgress()) } - if progress.TaskProgress != nil { - taskCallback(progress.TaskProgress) + if progress.GetTaskProgress() != nil { + taskCallback(progress.GetTaskProgress()) } } diff --git a/internal/cli/lib/examples.go b/internal/cli/lib/examples.go index 729a202d98b..11fadebdbef 100644 --- a/internal/cli/lib/examples.go +++ b/internal/cli/lib/examples.go @@ -76,8 +76,8 @@ func runExamplesCommand(cmd *cobra.Command, args []string) { found := []*libraryExamples{} for _, lib := range res.GetInstalledLibraries() { found = append(found, &libraryExamples{ - Library: result.NewLibrary(lib.Library), - Examples: lib.Library.Examples, + Library: result.NewLibrary(lib.GetLibrary()), + Examples: lib.GetLibrary().GetExamples(), }) } diff --git a/internal/cli/lib/list.go b/internal/cli/lib/list.go index 8c489b102f5..27a69fd3d15 100644 --- a/internal/cli/lib/list.go +++ b/internal/cli/lib/list.go @@ -100,7 +100,7 @@ func GetList( libs = res.GetInstalledLibraries() } else { for _, lib := range res.GetInstalledLibraries() { - if lib.Library.CompatibleWith[fqbn.String()] { + if lib.GetLibrary().GetCompatibleWith()[fqbn.String()] { libs = append(libs, lib) } } diff --git a/internal/cli/monitor/monitor.go b/internal/cli/monitor/monitor.go index c48fbfac0e0..5162cb01815 100644 --- a/internal/cli/monitor/monitor.go +++ b/internal/cli/monitor/monitor.go @@ -155,8 +155,8 @@ func runMonitorCmd( feedback.Fatal(tr("Error getting port settings details: %s", err), feedback.ErrGeneric) } if describe { - settings := make([]*result.MonitorPortSettingDescriptor, len(enumerateResp.Settings)) - for i, v := range enumerateResp.Settings { + settings := make([]*result.MonitorPortSettingDescriptor, len(enumerateResp.GetSettings())) + for i, v := range enumerateResp.GetSettings() { settings[i] = result.NewMonitorPortSettingDescriptor(v) } feedback.PrintResult(&detailsResult{Settings: settings}) @@ -177,13 +177,13 @@ func runMonitorCmd( var setting *rpc.MonitorPortSettingDescriptor for _, s := range enumerateResp.GetSettings() { if k == "" { - if contains(s.EnumValues, v) { + if contains(s.GetEnumValues(), v) { setting = s break } } else { - if strings.EqualFold(s.SettingId, k) { - if !contains(s.EnumValues, v) { + if strings.EqualFold(s.GetSettingId(), k) { + if !contains(s.GetEnumValues(), v) { feedback.Fatal(tr("invalid port configuration value for %s: %s", k, v), feedback.ErrBadArgument) } setting = s @@ -194,13 +194,13 @@ func runMonitorCmd( if setting == nil { feedback.Fatal(tr("invalid port configuration: %s", config), feedback.ErrBadArgument) } - configuration.Settings = append(configuration.Settings, &rpc.MonitorPortSetting{ - SettingId: setting.SettingId, + configuration.Settings = append(configuration.GetSettings(), &rpc.MonitorPortSetting{ + SettingId: setting.GetSettingId(), Value: v, }) if !quiet { feedback.Print(tr("Monitor port settings:")) - feedback.Print(fmt.Sprintf("%s=%s", setting.SettingId, v)) + feedback.Print(fmt.Sprintf("%s=%s", setting.GetSettingId(), v)) } } } diff --git a/internal/cli/upload/upload.go b/internal/cli/upload/upload.go index 7bbc868bf9b..7af3e4bcbfb 100644 --- a/internal/cli/upload/upload.go +++ b/internal/cli/upload/upload.go @@ -122,7 +122,7 @@ func runUploadCommand(args []string, uploadFieldsArgs map[string]string) { userFieldRes, err := upload.SupportedUserFields(context.Background(), &rpc.SupportedUserFieldsRequest{ Instance: inst, Fqbn: fqbn, - Protocol: port.Protocol, + Protocol: port.GetProtocol(), }) if err != nil { msg := tr("Error during Upload: %v", err) @@ -152,20 +152,20 @@ func runUploadCommand(args []string, uploadFieldsArgs map[string]string) { } fields := map[string]string{} - if len(userFieldRes.UserFields) > 0 { + if len(userFieldRes.GetUserFields()) > 0 { if len(uploadFieldsArgs) > 0 { // If the user has specified some fields via cmd-line, we don't ask for them - for _, field := range userFieldRes.UserFields { - if value, ok := uploadFieldsArgs[field.Name]; ok { - fields[field.Name] = value + for _, field := range userFieldRes.GetUserFields() { + if value, ok := uploadFieldsArgs[field.GetName()]; ok { + fields[field.GetName()] = value } else { - feedback.Fatal(tr("Missing required upload field: %s", field.Name), feedback.ErrBadArgument) + feedback.Fatal(tr("Missing required upload field: %s", field.GetName()), feedback.ErrBadArgument) } } } else { // Otherwise prompt the user for them - feedback.Print(tr("Uploading to specified board using %s protocol requires the following info:", port.Protocol)) - if f, err := arguments.AskForUserFields(userFieldRes.UserFields); err != nil { + feedback.Print(tr("Uploading to specified board using %s protocol requires the following info:", port.GetProtocol())) + if f, err := arguments.AskForUserFields(userFieldRes.GetUserFields()); err != nil { msg := fmt.Sprintf("%s: %s", tr("Error getting user input"), err) feedback.Fatal(msg, feedback.ErrGeneric) } else { diff --git a/internal/integrationtest/arduino-cli.go b/internal/integrationtest/arduino-cli.go index c2b10f7e121..bf240fc19bd 100644 --- a/internal/integrationtest/arduino-cli.go +++ b/internal/integrationtest/arduino-cli.go @@ -409,7 +409,7 @@ func (cli *ArduinoCLI) Create() *ArduinoCLIInstance { logCallf(" -> %v\n", resp) return &ArduinoCLIInstance{ cli: cli, - instance: resp.Instance, + instance: resp.GetInstance(), } } diff --git a/internal/integrationtest/daemon/daemon_test.go b/internal/integrationtest/daemon/daemon_test.go index 6c02b5f3b22..25df9e25aa2 100644 --- a/internal/integrationtest/daemon/daemon_test.go +++ b/internal/integrationtest/daemon/daemon_test.go @@ -75,7 +75,7 @@ func TestArduinoCliDaemon(t *testing.T) { return } require.NoError(t, err, "BoardListWatch grpc call returned an error") - require.Empty(t, msg.Error, "Board list watcher returned an error") + require.Empty(t, msg.GetError(), "Board list watcher returned an error") fmt.Printf("WATCH> %v %v\n", msg, err) } }() @@ -173,7 +173,7 @@ func TestDaemonCompileOptions(t *testing.T) { fmt.Println("COMPILE ERROR>", err) break } - if msg.ErrStream != nil { + if msg.GetErrStream() != nil { fmt.Printf("COMPILE> %v\n", string(msg.GetErrStream())) } } @@ -188,7 +188,7 @@ func TestDaemonCompileOptions(t *testing.T) { break } require.NoError(t, err) - if msg.ErrStream != nil { + if msg.GetErrStream() != nil { fmt.Printf("COMPILE> %v\n", string(msg.GetErrStream())) } analyzer.Process(msg.GetProgress()) @@ -196,7 +196,7 @@ func TestDaemonCompileOptions(t *testing.T) { // https://github.com/arduino/arduino-cli/issues/2016 // assert that the task progress is increasing and doesn't contain multiple 100% values results := analyzer.Results[""] - require.True(t, results[len(results)-1].Completed, fmt.Sprintf("latest percent value: %v", results[len(results)-1].Percent)) + require.True(t, results[len(results)-1].GetCompleted(), fmt.Sprintf("latest percent value: %v", results[len(results)-1].GetPercent())) require.IsNonDecreasing(t, f.Map(results, (*commands.TaskProgress).GetPercent)) } @@ -226,7 +226,7 @@ func TestDaemonCompileAfterFailedLibInstall(t *testing.T) { require.Contains(t, err.Error(), "Missing FQBN") break } - if msg.ErrStream != nil { + if msg.GetErrStream() != nil { fmt.Printf("COMPILE> %v\n", string(msg.GetErrStream())) } } @@ -254,7 +254,7 @@ func TestDaemonCoreUpdateIndex(t *testing.T) { res, err := analyzeUpdateIndexClient(t, cl) require.NoError(t, err) require.Len(t, res, 1) - require.True(t, res["https://downloads.arduino.cc/packages/package_index.tar.bz2"].Success) + require.True(t, res["https://downloads.arduino.cc/packages/package_index.tar.bz2"].GetSuccess()) } { cl, err := grpcInst.UpdateIndex(context.Background(), false) @@ -262,9 +262,9 @@ func TestDaemonCoreUpdateIndex(t *testing.T) { res, err := analyzeUpdateIndexClient(t, cl) require.Error(t, err) require.Len(t, res, 3) - require.True(t, res["https://downloads.arduino.cc/packages/package_index.tar.bz2"].Success) - require.True(t, res["http://arduino.esp8266.com/stable/package_esp8266com_index.json"].Success) - require.False(t, res["http://downloads.arduino.cc/package_inexistent_index.json"].Success) + require.True(t, res["https://downloads.arduino.cc/packages/package_index.tar.bz2"].GetSuccess()) + require.True(t, res["http://arduino.esp8266.com/stable/package_esp8266com_index.json"].GetSuccess()) + require.False(t, res["http://downloads.arduino.cc/package_inexistent_index.json"].GetSuccess()) } } @@ -297,7 +297,7 @@ func TestDaemonBundleLibInstall(t *testing.T) { require.NoError(t, err) libsAndLocation := map[string]commands.LibraryLocation{} for _, lib := range resp.GetInstalledLibraries() { - libsAndLocation[lib.Library.Name] = lib.Library.Location + libsAndLocation[lib.GetLibrary().GetName()] = lib.GetLibrary().GetLocation() } require.Contains(t, libsAndLocation, "Ethernet") require.Contains(t, libsAndLocation, "SD") @@ -328,9 +328,9 @@ func TestDaemonBundleLibInstall(t *testing.T) { require.NoError(t, err) libsAndLocation := map[string]commands.LibraryLocation{} for _, lib := range resp.GetInstalledLibraries() { - libsAndLocation[lib.Library.Name] = lib.Library.Location - if lib.Library.Name == "Ethernet" { - installedEthernetVersion = lib.Library.Version + libsAndLocation[lib.GetLibrary().GetName()] = lib.GetLibrary().GetLocation() + if lib.GetLibrary().GetName() == "Ethernet" { + installedEthernetVersion = lib.GetLibrary().GetVersion() } } require.Contains(t, libsAndLocation, "Ethernet") @@ -361,7 +361,7 @@ func TestDaemonBundleLibInstall(t *testing.T) { require.NoError(t, err) libsAndLocation := map[string]commands.LibraryLocation{} for _, lib := range resp.GetInstalledLibraries() { - libsAndLocation[lib.Library.Name] = lib.Library.Location + libsAndLocation[lib.GetLibrary().GetName()] = lib.GetLibrary().GetLocation() } require.Contains(t, libsAndLocation, "Ethernet") require.Contains(t, libsAndLocation, "SD") @@ -447,7 +447,7 @@ func TestDaemonCoreUpgradePlatform(t *testing.T) { res, err := analyzeUpdateIndexClient(t, cl) require.NoError(t, err) require.Len(t, res, 2) - require.True(t, res["https://arduino.esp8266.com/stable/package_esp8266com_index.json"].Success) + require.True(t, res["https://arduino.esp8266.com/stable/package_esp8266com_index.json"].GetSuccess()) refreshInstance(t, grpcInst) @@ -477,8 +477,8 @@ func TestDaemonCoreUpgradePlatform(t *testing.T) { platform, upgradeError := analyzePlatformUpgradeClient(plUpgrade) require.NoError(t, upgradeError) require.NotNil(t, platform) - require.True(t, platform.Metadata.Indexed) // the esp866 is present in the additional-urls - require.False(t, platform.Release.MissingMetadata) // install.json is present + require.True(t, platform.GetMetadata().GetIndexed()) // the esp866 is present in the additional-urls + require.False(t, platform.GetRelease().GetMissingMetadata()) // install.json is present }) t.Run("and install.json is missing", func(t *testing.T) { env, cli := createEnvForDaemon(t) @@ -497,8 +497,8 @@ func TestDaemonCoreUpgradePlatform(t *testing.T) { platform, upgradeError := analyzePlatformUpgradeClient(plUpgrade) require.NoError(t, upgradeError) require.NotNil(t, platform) - require.True(t, platform.Metadata.Indexed) // the esp866 is not present in the additional-urls - require.False(t, platform.Release.MissingMetadata) // install.json is present because the old version got upgraded + require.True(t, platform.GetMetadata().GetIndexed()) // the esp866 is not present in the additional-urls + require.False(t, platform.GetRelease().GetMissingMetadata()) // install.json is present because the old version got upgraded }) }) @@ -520,8 +520,8 @@ func TestDaemonCoreUpgradePlatform(t *testing.T) { platform, upgradeError := analyzePlatformUpgradeClient(plUpgrade) require.ErrorIs(t, upgradeError, (&arduino.PlatformAlreadyAtTheLatestVersionError{Platform: "esp8266:esp8266"}).ToRPCStatus().Err()) require.NotNil(t, platform) - require.False(t, platform.Metadata.Indexed) // the esp866 is not present in the additional-urls - require.False(t, platform.Release.MissingMetadata) // install.json is present + require.False(t, platform.GetMetadata().GetIndexed()) // the esp866 is not present in the additional-urls + require.False(t, platform.GetRelease().GetMissingMetadata()) // install.json is present }) t.Run("missing both additional URLs and install.json", func(t *testing.T) { env, cli := createEnvForDaemon(t) @@ -545,8 +545,8 @@ func TestDaemonCoreUpgradePlatform(t *testing.T) { platform, upgradeError := analyzePlatformUpgradeClient(plUpgrade) require.ErrorIs(t, upgradeError, (&arduino.PlatformAlreadyAtTheLatestVersionError{Platform: "esp8266:esp8266"}).ToRPCStatus().Err()) require.NotNil(t, platform) - require.False(t, platform.Metadata.Indexed) // the esp866 is not present in the additional-urls - require.True(t, platform.Release.MissingMetadata) // install.json is present + require.False(t, platform.GetMetadata().GetIndexed()) // the esp866 is not present in the additional-urls + require.True(t, platform.GetRelease().GetMissingMetadata()) // install.json is present }) }) } diff --git a/internal/integrationtest/daemon/download_progress_test.go b/internal/integrationtest/daemon/download_progress_test.go index a232abec033..b67bde71ab8 100644 --- a/internal/integrationtest/daemon/download_progress_test.go +++ b/internal/integrationtest/daemon/download_progress_test.go @@ -45,7 +45,7 @@ func (a *DownloadProgressAnalyzer) Process(progress *commands.DownloadProgress) } if start := progress.GetStart(); start != nil { require.Empty(a.t, a.ongoingDownload, "DownloadProgressStart: started a download without 'completing' the previous one") - a.ongoingDownload = start.Url + a.ongoingDownload = start.GetUrl() } else if update := progress.GetUpdate(); update != nil { require.NotEmpty(a.t, a.ongoingDownload, "DownloadProgressUpdate: received update, but the download is not yet started...") } else if end := progress.GetEnd(); end != nil { diff --git a/rpc/cc/arduino/cli/commands/v1/common.go b/rpc/cc/arduino/cli/commands/v1/common.go index a04ebff193f..529c6dfdfb4 100644 --- a/rpc/cc/arduino/cli/commands/v1/common.go +++ b/rpc/cc/arduino/cli/commands/v1/common.go @@ -72,19 +72,19 @@ type InstanceCommand interface { // GetLatestRelease returns the latest release in this PlatformSummary, // or nil if not available. func (s *PlatformSummary) GetLatestRelease() *PlatformRelease { - if s.LatestVersion == "" { + if s.GetLatestVersion() == "" { return nil } - return s.Releases[s.LatestVersion] + return s.GetReleases()[s.GetLatestVersion()] } // GetInstalledRelease returns the latest release in this PlatformSummary, // or nil if not available. func (s *PlatformSummary) GetInstalledRelease() *PlatformRelease { - if s.InstalledVersion == "" { + if s.GetInstalledVersion() == "" { return nil } - return s.Releases[s.InstalledVersion] + return s.GetReleases()[s.GetInstalledVersion()] } // GetSortedReleases returns the releases in order of version. @@ -94,7 +94,7 @@ func (s *PlatformSummary) GetSortedReleases() []*PlatformRelease { res = append(res, release) } sort.SliceStable(res, func(i, j int) bool { - return semver.ParseRelaxed(res[i].Version).LessThan(semver.ParseRelaxed(res[j].Version)) + return semver.ParseRelaxed(res[i].GetVersion()).LessThan(semver.ParseRelaxed(res[j].GetVersion())) }) return res }