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
}
rpcPlatform := &rpc.Platform{
Metadata: PlatformToRPCPlatformMetadata(platform),
Release: PlatformReleaseToRPC(installedPlatformRelease),
Metadata: platformToRPCPlatformMetadata(platform),
Release: platformReleaseToRPC(installedPlatformRelease),
}
toTest := []string{
......
......@@ -67,8 +67,8 @@ func (s *arduinoCoreServerImpl) BoardSearch(ctx context.Context, req *rpc.BoardS
Fqbn: board.FQBN(),
IsHidden: board.IsHidden(),
Platform: &rpc.Platform{
Metadata: PlatformToRPCPlatformMetadata(platform),
Release: PlatformReleaseToRPC(installedPlatformRelease),
Metadata: platformToRPCPlatformMetadata(platform),
Release: platformReleaseToRPC(installedPlatformRelease),
},
})
}
......@@ -82,8 +82,8 @@ func (s *arduinoCoreServerImpl) BoardSearch(ctx context.Context, req *rpc.BoardS
foundBoards = append(foundBoards, &rpc.BoardListItem{
Name: strings.Trim(board.Name, " \n"),
Platform: &rpc.Platform{
Metadata: PlatformToRPCPlatformMetadata(platform),
Release: PlatformReleaseToRPC(latestPlatformRelease),
Metadata: platformToRPCPlatformMetadata(platform),
Release: platformReleaseToRPC(latestPlatformRelease),
},
})
}
......
......@@ -56,7 +56,7 @@ func (s *arduinoCoreServerImpl) LibraryDownload(req *rpc.LibraryDownloadRequest,
return err
}
version, err := ParseVersion(req.GetVersion())
version, err := parseVersion(req.GetVersion())
if err != nil {
return err
}
......
......@@ -109,7 +109,7 @@ func (s *arduinoCoreServerImpl) LibraryInstall(req *rpc.LibraryInstallRequest, s
libReleasesToInstall := map[*librariesindex.Release]*librariesmanager.LibraryInstallPlan{}
installLocation := libraries.FromRPCLibraryInstallLocation(req.GetInstallLocation())
for _, lib := range toInstall {
version, err := ParseVersion(lib.GetVersionRequired())
version, err := parseVersion(lib.GetVersionRequired())
if err != nil {
return err
}
......
......@@ -47,7 +47,7 @@ func (s *arduinoCoreServerImpl) LibraryResolveDependencies(ctx context.Context,
func libraryResolveDependencies(lme *librariesmanager.Explorer, li *librariesindex.Index,
reqName, reqVersion string, noOverwrite bool) (*rpc.LibraryResolveDependenciesResponse, error) {
version, err := ParseVersion(reqVersion)
version, err := parseVersion(reqVersion)
if err != nil {
return nil, err
}
......
......@@ -47,7 +47,7 @@ func (s *arduinoCoreServerImpl) LibraryUninstall(req *rpc.LibraryUninstallReques
return err
}
version, err := ParseVersion(req.GetVersion())
version, err := parseVersion(req.GetVersion())
if err != nil {
return err
}
......
......@@ -48,7 +48,7 @@ func (s *arduinoCoreServerImpl) PlatformDownload(req *rpc.PlatformDownloadReques
}
defer release()
version, err := ParseVersion(req.GetVersion())
version, err := parseVersion(req.GetVersion())
if err != nil {
return &cmderrors.InvalidVersionError{Cause: err}
}
......
......@@ -53,7 +53,7 @@ func (s *arduinoCoreServerImpl) PlatformInstall(req *rpc.PlatformInstallRequest,
}
defer release()
version, err := ParseVersion(req.GetVersion())
version, err := parseVersion(req.GetVersion())
if err != nil {
return &cmderrors.InvalidVersionError{Cause: err}
}
......
......@@ -82,7 +82,7 @@ func (s *arduinoCoreServerImpl) PlatformSearch(_ context.Context, req *rpc.Platf
out := []*rpc.PlatformSummary{}
for _, platform := range res {
rpcPlatformSummary := &rpc.PlatformSummary{
Metadata: PlatformToRPCPlatformMetadata(platform),
Metadata: platformToRPCPlatformMetadata(platform),
Releases: map[string]*rpc.PlatformRelease{},
}
if installed := pme.GetInstalledPlatformRelease(platform); installed != nil {
......@@ -92,7 +92,7 @@ func (s *arduinoCoreServerImpl) PlatformSearch(_ context.Context, req *rpc.Platf
rpcPlatformSummary.LatestVersion = latestCompatible.Version.String()
}
for _, platformRelease := range platform.GetAllReleases() {
rpcPlatformRelease := PlatformReleaseToRPC(platformRelease)
rpcPlatformRelease := platformReleaseToRPC(platformRelease)
rpcPlatformSummary.Releases[rpcPlatformRelease.GetVersion()] = rpcPlatformRelease
}
out = append(out, rpcPlatformSummary)
......
......@@ -76,8 +76,8 @@ func (s *arduinoCoreServerImpl) PlatformUpgrade(req *rpc.PlatformUpgradeRequest,
if platformRelease != nil {
syncSend.Send(&rpc.PlatformUpgradeResponse{
Platform: &rpc.Platform{
Metadata: PlatformToRPCPlatformMetadata(platformRelease.Platform),
Release: PlatformReleaseToRPC(platformRelease),
Metadata: platformToRPCPlatformMetadata(platformRelease.Platform),
Release: platformReleaseToRPC(platformRelease),
},
})
}
......
......@@ -20,8 +20,8 @@ import (
rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1"
)
// PlatformToRPCPlatformMetadata converts our internal structure to the RPC structure.
func PlatformToRPCPlatformMetadata(platform *cores.Platform) *rpc.PlatformMetadata {
// platformToRPCPlatformMetadata converts our internal structure to the RPC structure.
func platformToRPCPlatformMetadata(platform *cores.Platform) *rpc.PlatformMetadata {
return &rpc.PlatformMetadata{
Id: platform.String(),
Maintainer: platform.Package.Maintainer,
......@@ -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
// 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.
// In such case, we have to use the `platformRelease.BoardsManifest` instead.
// So that we can retrieve the name of the boards at least.
......
......@@ -20,10 +20,10 @@ import (
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
// semver.
func ParseVersion(version string) (*semver.Version, error) {
func parseVersion(version string) (*semver.Version, error) {
if version == "" {
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