Skip to content

Use grpc enumerations for LibraryLayout and LibraryLocation #613

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions arduino/libraries/libraries_layout.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ package libraries
import (
"encoding/json"
"fmt"

rpc "github.com/arduino/arduino-cli/rpc/commands"
)

// LibraryLayout represents how the library source code is laid out in the library
Expand Down Expand Up @@ -65,3 +67,14 @@ func (d *LibraryLayout) UnmarshalJSON(b []byte) error {
}
return fmt.Errorf("invalid library layout: %s", s)
}

// ToRPCLibraryLayout converts this LibraryLayout to rpc.LibraryLayout
func (d *LibraryLayout) ToRPCLibraryLayout() rpc.LibraryLayout {
switch *d {
case FlatLayout:
return rpc.LibraryLayout_flat_layout
case RecursiveLayout:
return rpc.LibraryLayout_recursive_layout
}
panic(fmt.Sprintf("invalid LibraryLayout value %d", *d))
}
32 changes: 32 additions & 0 deletions arduino/libraries/libraries_location.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ package libraries
import (
"encoding/json"
"fmt"

rpc "github.com/arduino/arduino-cli/rpc/commands"
)

// LibraryLocation represents where the library is installed
Expand Down Expand Up @@ -82,3 +84,33 @@ func (d *LibraryLocation) UnmarshalJSON(b []byte) error {
}
return fmt.Errorf("invalid library location: %s", s)
}

// ToRPCLibraryLocation converts this LibraryLocation to rpc.LibraryLocation
func (d *LibraryLocation) ToRPCLibraryLocation() rpc.LibraryLocation {
switch *d {
case IDEBuiltIn:
return rpc.LibraryLocation_ide_builtin
case PlatformBuiltIn:
return rpc.LibraryLocation_platform_builtin
case ReferencedPlatformBuiltIn:
return rpc.LibraryLocation_referenced_platform_builtin
case User:
return rpc.LibraryLocation_user
}
panic(fmt.Sprintf("invalid LibraryLocation value %d", *d))
}

// FromRPCLibraryLocation converts a rpc.LibraryLocation to a LibraryLocation
func FromRPCLibraryLocation(l rpc.LibraryLocation) LibraryLocation {
switch l {
case rpc.LibraryLocation_ide_builtin:
return IDEBuiltIn
case rpc.LibraryLocation_platform_builtin:
return PlatformBuiltIn
case rpc.LibraryLocation_referenced_platform_builtin:
return ReferencedPlatformBuiltIn
case rpc.LibraryLocation_user:
return User
}
panic(fmt.Sprintf("invalid rpc.LibraryLocation value %d", l))
}
2 changes: 1 addition & 1 deletion cli/lib/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func (ir installedResult) String() string {
lastName = name
}

location := lib.GetLocation()
location := lib.GetLocation().String()
if lib.ContainerPlatform != "" {
location = lib.GetContainerPlatform()
}
Expand Down
4 changes: 2 additions & 2 deletions commands/lib/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,9 @@ func GetOutputLibrary(lib *libraries.Library) *rpc.Library {
InstallDir: insdir,
SourceDir: srcdir,
UtilityDir: utldir,
Location: lib.Location.String(),
Location: lib.Location.ToRPCLibraryLocation(),
ContainerPlatform: cntplat,
Layout: lib.Layout.String(),
Layout: lib.Layout.ToRPCLibraryLayout(),
RealName: lib.RealName,
DotALinkage: lib.DotALinkage,
Precompiled: lib.Precompiled,
Expand Down
Loading