Commit 3193b7c4 authored by Cristian Maglie's avatar Cristian Maglie

Made utility functions private and put them in their own file

parent 0bdc07ab
...@@ -46,8 +46,8 @@ func (s *arduinoCoreServerImpl) BoardListAll(ctx context.Context, req *rpc.Board ...@@ -46,8 +46,8 @@ func (s *arduinoCoreServerImpl) BoardListAll(ctx context.Context, req *rpc.Board
} }
rpcPlatform := &rpc.Platform{ rpcPlatform := &rpc.Platform{
Metadata: PlatformToRPCPlatformMetadata(platform), Metadata: platformToRPCPlatformMetadata(platform),
Release: PlatformReleaseToRPC(installedPlatformRelease), Release: platformReleaseToRPC(installedPlatformRelease),
} }
toTest := []string{ toTest := []string{
......
...@@ -67,8 +67,8 @@ func (s *arduinoCoreServerImpl) BoardSearch(ctx context.Context, req *rpc.BoardS ...@@ -67,8 +67,8 @@ func (s *arduinoCoreServerImpl) BoardSearch(ctx context.Context, req *rpc.BoardS
Fqbn: board.FQBN(), Fqbn: board.FQBN(),
IsHidden: board.IsHidden(), IsHidden: board.IsHidden(),
Platform: &rpc.Platform{ Platform: &rpc.Platform{
Metadata: PlatformToRPCPlatformMetadata(platform), Metadata: platformToRPCPlatformMetadata(platform),
Release: PlatformReleaseToRPC(installedPlatformRelease), Release: platformReleaseToRPC(installedPlatformRelease),
}, },
}) })
} }
...@@ -82,8 +82,8 @@ func (s *arduinoCoreServerImpl) BoardSearch(ctx context.Context, req *rpc.BoardS ...@@ -82,8 +82,8 @@ func (s *arduinoCoreServerImpl) BoardSearch(ctx context.Context, req *rpc.BoardS
foundBoards = append(foundBoards, &rpc.BoardListItem{ foundBoards = append(foundBoards, &rpc.BoardListItem{
Name: strings.Trim(board.Name, " \n"), Name: strings.Trim(board.Name, " \n"),
Platform: &rpc.Platform{ Platform: &rpc.Platform{
Metadata: PlatformToRPCPlatformMetadata(platform), Metadata: platformToRPCPlatformMetadata(platform),
Release: PlatformReleaseToRPC(latestPlatformRelease), Release: platformReleaseToRPC(latestPlatformRelease),
}, },
}) })
} }
......
...@@ -56,7 +56,7 @@ func (s *arduinoCoreServerImpl) LibraryDownload(req *rpc.LibraryDownloadRequest, ...@@ -56,7 +56,7 @@ func (s *arduinoCoreServerImpl) LibraryDownload(req *rpc.LibraryDownloadRequest,
return err return err
} }
version, err := ParseVersion(req.GetVersion()) version, err := parseVersion(req.GetVersion())
if err != nil { if err != nil {
return err return err
} }
......
...@@ -109,7 +109,7 @@ func (s *arduinoCoreServerImpl) LibraryInstall(req *rpc.LibraryInstallRequest, s ...@@ -109,7 +109,7 @@ func (s *arduinoCoreServerImpl) LibraryInstall(req *rpc.LibraryInstallRequest, s
libReleasesToInstall := map[*librariesindex.Release]*librariesmanager.LibraryInstallPlan{} libReleasesToInstall := map[*librariesindex.Release]*librariesmanager.LibraryInstallPlan{}
installLocation := libraries.FromRPCLibraryInstallLocation(req.GetInstallLocation()) installLocation := libraries.FromRPCLibraryInstallLocation(req.GetInstallLocation())
for _, lib := range toInstall { for _, lib := range toInstall {
version, err := ParseVersion(lib.GetVersionRequired()) version, err := parseVersion(lib.GetVersionRequired())
if err != nil { if err != nil {
return err return err
} }
......
...@@ -47,7 +47,7 @@ func (s *arduinoCoreServerImpl) LibraryResolveDependencies(ctx context.Context, ...@@ -47,7 +47,7 @@ func (s *arduinoCoreServerImpl) LibraryResolveDependencies(ctx context.Context,
func libraryResolveDependencies(lme *librariesmanager.Explorer, li *librariesindex.Index, func libraryResolveDependencies(lme *librariesmanager.Explorer, li *librariesindex.Index,
reqName, reqVersion string, noOverwrite bool) (*rpc.LibraryResolveDependenciesResponse, error) { reqName, reqVersion string, noOverwrite bool) (*rpc.LibraryResolveDependenciesResponse, error) {
version, err := ParseVersion(reqVersion) version, err := parseVersion(reqVersion)
if err != nil { if err != nil {
return nil, err return nil, err
} }
......
...@@ -47,7 +47,7 @@ func (s *arduinoCoreServerImpl) LibraryUninstall(req *rpc.LibraryUninstallReques ...@@ -47,7 +47,7 @@ func (s *arduinoCoreServerImpl) LibraryUninstall(req *rpc.LibraryUninstallReques
return err return err
} }
version, err := ParseVersion(req.GetVersion()) version, err := parseVersion(req.GetVersion())
if err != nil { if err != nil {
return err return err
} }
......
...@@ -48,7 +48,7 @@ func (s *arduinoCoreServerImpl) PlatformDownload(req *rpc.PlatformDownloadReques ...@@ -48,7 +48,7 @@ func (s *arduinoCoreServerImpl) PlatformDownload(req *rpc.PlatformDownloadReques
} }
defer release() defer release()
version, err := ParseVersion(req.GetVersion()) version, err := parseVersion(req.GetVersion())
if err != nil { if err != nil {
return &cmderrors.InvalidVersionError{Cause: err} return &cmderrors.InvalidVersionError{Cause: err}
} }
......
...@@ -53,7 +53,7 @@ func (s *arduinoCoreServerImpl) PlatformInstall(req *rpc.PlatformInstallRequest, ...@@ -53,7 +53,7 @@ func (s *arduinoCoreServerImpl) PlatformInstall(req *rpc.PlatformInstallRequest,
} }
defer release() defer release()
version, err := ParseVersion(req.GetVersion()) version, err := parseVersion(req.GetVersion())
if err != nil { if err != nil {
return &cmderrors.InvalidVersionError{Cause: err} return &cmderrors.InvalidVersionError{Cause: err}
} }
......
...@@ -82,7 +82,7 @@ func (s *arduinoCoreServerImpl) PlatformSearch(_ context.Context, req *rpc.Platf ...@@ -82,7 +82,7 @@ func (s *arduinoCoreServerImpl) PlatformSearch(_ context.Context, req *rpc.Platf
out := []*rpc.PlatformSummary{} out := []*rpc.PlatformSummary{}
for _, platform := range res { for _, platform := range res {
rpcPlatformSummary := &rpc.PlatformSummary{ rpcPlatformSummary := &rpc.PlatformSummary{
Metadata: PlatformToRPCPlatformMetadata(platform), Metadata: platformToRPCPlatformMetadata(platform),
Releases: map[string]*rpc.PlatformRelease{}, Releases: map[string]*rpc.PlatformRelease{},
} }
if installed := pme.GetInstalledPlatformRelease(platform); installed != nil { if installed := pme.GetInstalledPlatformRelease(platform); installed != nil {
...@@ -92,7 +92,7 @@ func (s *arduinoCoreServerImpl) PlatformSearch(_ context.Context, req *rpc.Platf ...@@ -92,7 +92,7 @@ func (s *arduinoCoreServerImpl) PlatformSearch(_ context.Context, req *rpc.Platf
rpcPlatformSummary.LatestVersion = latestCompatible.Version.String() rpcPlatformSummary.LatestVersion = latestCompatible.Version.String()
} }
for _, platformRelease := range platform.GetAllReleases() { for _, platformRelease := range platform.GetAllReleases() {
rpcPlatformRelease := PlatformReleaseToRPC(platformRelease) rpcPlatformRelease := platformReleaseToRPC(platformRelease)
rpcPlatformSummary.Releases[rpcPlatformRelease.GetVersion()] = rpcPlatformRelease rpcPlatformSummary.Releases[rpcPlatformRelease.GetVersion()] = rpcPlatformRelease
} }
out = append(out, rpcPlatformSummary) out = append(out, rpcPlatformSummary)
......
...@@ -76,8 +76,8 @@ func (s *arduinoCoreServerImpl) PlatformUpgrade(req *rpc.PlatformUpgradeRequest, ...@@ -76,8 +76,8 @@ func (s *arduinoCoreServerImpl) PlatformUpgrade(req *rpc.PlatformUpgradeRequest,
if platformRelease != nil { if platformRelease != nil {
syncSend.Send(&rpc.PlatformUpgradeResponse{ syncSend.Send(&rpc.PlatformUpgradeResponse{
Platform: &rpc.Platform{ Platform: &rpc.Platform{
Metadata: PlatformToRPCPlatformMetadata(platformRelease.Platform), Metadata: platformToRPCPlatformMetadata(platformRelease.Platform),
Release: PlatformReleaseToRPC(platformRelease), Release: platformReleaseToRPC(platformRelease),
}, },
}) })
} }
......
...@@ -20,8 +20,8 @@ import ( ...@@ -20,8 +20,8 @@ import (
rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1" rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1"
) )
// PlatformToRPCPlatformMetadata converts our internal structure to the RPC structure. // platformToRPCPlatformMetadata converts our internal structure to the RPC structure.
func PlatformToRPCPlatformMetadata(platform *cores.Platform) *rpc.PlatformMetadata { func platformToRPCPlatformMetadata(platform *cores.Platform) *rpc.PlatformMetadata {
return &rpc.PlatformMetadata{ return &rpc.PlatformMetadata{
Id: platform.String(), Id: platform.String(),
Maintainer: platform.Package.Maintainer, Maintainer: platform.Package.Maintainer,
...@@ -33,10 +33,10 @@ func PlatformToRPCPlatformMetadata(platform *cores.Platform) *rpc.PlatformMetada ...@@ -33,10 +33,10 @@ func PlatformToRPCPlatformMetadata(platform *cores.Platform) *rpc.PlatformMetada
} }
} }
// PlatformReleaseToRPC converts our internal structure to the RPC structure. // platformReleaseToRPC converts our internal structure to the RPC structure.
// Note: this function does not touch the "Installed" field of rpc.Platform as it's not always clear that the // Note: this function does not touch the "Installed" field of rpc.Platform as it's not always clear that the
// platformRelease we're currently converting is actually installed. // platformRelease we're currently converting is actually installed.
func PlatformReleaseToRPC(platformRelease *cores.PlatformRelease) *rpc.PlatformRelease { func platformReleaseToRPC(platformRelease *cores.PlatformRelease) *rpc.PlatformRelease {
// If the boards are not installed yet, the `platformRelease.Boards` will be a zero length slice. // If the boards are not installed yet, the `platformRelease.Boards` will be a zero length slice.
// In such case, we have to use the `platformRelease.BoardsManifest` instead. // In such case, we have to use the `platformRelease.BoardsManifest` instead.
// So that we can retrieve the name of the boards at least. // So that we can retrieve the name of the boards at least.
......
...@@ -20,10 +20,10 @@ import ( ...@@ -20,10 +20,10 @@ import (
semver "go.bug.st/relaxed-semver" semver "go.bug.st/relaxed-semver"
) )
// ParseVersion returns the parsed version or nil if the version is // parseVersion returns the parsed version or nil if the version is
// the empty string. An error is returned if the version is not valid // the empty string. An error is returned if the version is not valid
// semver. // semver.
func ParseVersion(version string) (*semver.Version, error) { func parseVersion(version string) (*semver.Version, error) {
if version == "" { if version == "" {
return nil, nil return nil, nil
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment