Skip to content

Commit

Permalink
Made utility functions private and put them in their own file
Browse files Browse the repository at this point in the history
  • Loading branch information
cmaglie committed Mar 19, 2024
1 parent 2036d5d commit 99645aa
Show file tree
Hide file tree
Showing 14 changed files with 22 additions and 22 deletions.
4 changes: 2 additions & 2 deletions commands/service_board_listall.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
8 changes: 4 additions & 4 deletions commands/service_board_search.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
},
})
}
Expand All @@ -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),
},
})
}
Expand Down
2 changes: 1 addition & 1 deletion commands/service_library_download.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion commands/service_library_install.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion commands/service_library_resolve_deps.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion commands/service_library_uninstall.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion commands/service_platform_download.go
Original file line number Diff line number Diff line change
Expand Up @@ -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}
}
Expand Down
2 changes: 1 addition & 1 deletion commands/service_platform_install.go
Original file line number Diff line number Diff line change
Expand Up @@ -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}
}
Expand Down
4 changes: 2 additions & 2 deletions commands/service_platform_search.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions commands/service_platform_upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
},
})
}
Expand Down
8 changes: 4 additions & 4 deletions commands/core.go → commands/utility_core.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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.
Expand Down
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions commands/version.go → commands/utility_version.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit 99645aa

Please sign in to comment.