Skip to content

Added 'dependencies', 'license' and 'provides_includes' fields in lib search #599

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 3 commits into from
Feb 28, 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
24 changes: 13 additions & 11 deletions arduino/libraries/librariesindex/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,19 @@ type Library struct {

// Release is a release of a library available for download
type Release struct {
Author string
Version *semver.Version
Dependencies []semver.Dependency
Maintainer string
Sentence string
Paragraph string
Website string
Category string
Architectures []string
Types []string
Resource *resources.DownloadResource
Author string
Version *semver.Version
Dependencies []semver.Dependency
Maintainer string
Sentence string
Paragraph string
Website string
Category string
Architectures []string
Types []string
Resource *resources.DownloadResource
License string
ProvidesIncludes []string

Library *Library `json:"-"`
}
Expand Down
38 changes: 21 additions & 17 deletions arduino/libraries/librariesindex/json.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,21 +29,23 @@ type indexJSON struct {
}

type indexRelease struct {
Name string `json:"name,required"`
Version *semver.Version `json:"version,required"`
Author string `json:"author"`
Maintainer string `json:"maintainer"`
Sentence string `json:"sentence"`
Paragraph string `json:"paragraph"`
Website string `json:"website"`
Category string `json:"category"`
Architectures []string `json:"architectures"`
Types []string `json:"types"`
URL string `json:"url"`
ArchiveFileName string `json:"archiveFileName"`
Size int64 `json:"size"`
Checksum string `json:"checksum"`
Dependencies []*indexDependency `json:"dependencies,omitempty"`
Name string `json:"name,required"`
Version *semver.Version `json:"version,required"`
Author string `json:"author"`
Maintainer string `json:"maintainer"`
Sentence string `json:"sentence"`
Paragraph string `json:"paragraph"`
Website string `json:"website"`
Category string `json:"category"`
Architectures []string `json:"architectures"`
Types []string `json:"types"`
URL string `json:"url"`
ArchiveFileName string `json:"archiveFileName"`
Size int64 `json:"size"`
Checksum string `json:"checksum"`
Dependencies []*indexDependency `json:"dependencies,omitempty"`
License string `json:"license"`
ProvidesIncludes []string `json:"providesIncludes"`
}

type indexDependency struct {
Expand Down Expand Up @@ -107,8 +109,10 @@ func (indexLib *indexRelease) extractReleaseIn(library *Library) {
Checksum: indexLib.Checksum,
CachePath: "libraries",
},
Library: library,
Dependencies: indexLib.extractDependencies(),
Library: library,
Dependencies: indexLib.extractDependencies(),
License: indexLib.License,
ProvidesIncludes: indexLib.ProvidesIncludes,
}
library.Releases[indexLib.Version.String()] = release
if library.Latest == nil || library.Latest.Version.LessThan(release.Version) {
Expand Down
42 changes: 31 additions & 11 deletions cli/lib/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,21 +113,41 @@ func (res result) String() string {

var out strings.Builder

for _, lsr := range results {
out.WriteString(fmt.Sprintf("Name: \"%s\"\n", lsr.Name))
for _, lib := range results {
out.WriteString(fmt.Sprintf("Name: \"%s\"\n", lib.Name))
if res.namesOnly {
continue
}

out.WriteString(fmt.Sprintf(" Author: %s\n", lsr.GetLatest().Author))
out.WriteString(fmt.Sprintf(" Maintainer: %s\n", lsr.GetLatest().Maintainer))
out.WriteString(fmt.Sprintf(" Sentence: %s\n", lsr.GetLatest().Sentence))
out.WriteString(fmt.Sprintf(" Paragraph: %s\n", lsr.GetLatest().Paragraph))
out.WriteString(fmt.Sprintf(" Website: %s\n", lsr.GetLatest().Website))
out.WriteString(fmt.Sprintf(" Category: %s\n", lsr.GetLatest().Category))
out.WriteString(fmt.Sprintf(" Architecture: %s\n", strings.Join(lsr.GetLatest().Architectures, ", ")))
out.WriteString(fmt.Sprintf(" Types: %s\n", strings.Join(lsr.GetLatest().Types, ", ")))
out.WriteString(fmt.Sprintf(" Versions: %s\n", strings.Replace(fmt.Sprint(versionsFromSearchedLibrary(lsr)), " ", ", ", -1)))
latest := lib.GetLatest()

deps := []string{}
for _, dep := range latest.GetDependencies() {
if dep.GetVersionConstraint() == "" {
deps = append(deps, dep.GetName())
} else {
deps = append(deps, dep.GetName()+" ("+dep.GetVersionConstraint()+")")
}
}

out.WriteString(fmt.Sprintf(" Author: %s\n", latest.Author))
out.WriteString(fmt.Sprintf(" Maintainer: %s\n", latest.Maintainer))
out.WriteString(fmt.Sprintf(" Sentence: %s\n", latest.Sentence))
out.WriteString(fmt.Sprintf(" Paragraph: %s\n", latest.Paragraph))
out.WriteString(fmt.Sprintf(" Website: %s\n", latest.Website))
if latest.License != "" {
out.WriteString(fmt.Sprintf(" License: %s\n", latest.License))
}
out.WriteString(fmt.Sprintf(" Category: %s\n", latest.Category))
out.WriteString(fmt.Sprintf(" Architecture: %s\n", strings.Join(latest.Architectures, ", ")))
out.WriteString(fmt.Sprintf(" Types: %s\n", strings.Join(latest.Types, ", ")))
out.WriteString(fmt.Sprintf(" Versions: %s\n", strings.Replace(fmt.Sprint(versionsFromSearchedLibrary(lib)), " ", ", ", -1)))
if len(latest.ProvidesIncludes) > 0 {
out.WriteString(fmt.Sprintf(" Provides includes: %s\n", strings.Join(latest.ProvidesIncludes, ", ")))
}
if len(latest.Dependencies) > 0 {
out.WriteString(fmt.Sprintf(" Dependencies: %s\n", strings.Join(deps, ", ")))
}
}

return fmt.Sprintf("%s", out.String())
Expand Down
33 changes: 24 additions & 9 deletions commands/lib/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"github.com/arduino/arduino-cli/arduino/libraries/librariesindex"
"github.com/arduino/arduino-cli/commands"
rpc "github.com/arduino/arduino-cli/rpc/commands"
semver "go.bug.st/relaxed-semver"
)

// LibrarySearch FIXMEDOC
Expand Down Expand Up @@ -60,15 +61,18 @@ func LibrarySearch(ctx context.Context, req *rpc.LibrarySearchReq) (*rpc.Library
// GetLibraryParameters FIXMEDOC
func GetLibraryParameters(rel *librariesindex.Release) *rpc.LibraryRelease {
return &rpc.LibraryRelease{
Author: rel.Author,
Version: rel.Version.String(),
Maintainer: rel.Maintainer,
Sentence: rel.Sentence,
Paragraph: rel.Paragraph,
Website: rel.Website,
Category: rel.Category,
Architectures: rel.Architectures,
Types: rel.Types,
Author: rel.Author,
Version: rel.Version.String(),
Maintainer: rel.Maintainer,
Sentence: rel.Sentence,
Paragraph: rel.Paragraph,
Website: rel.Website,
Category: rel.Category,
Architectures: rel.Architectures,
Types: rel.Types,
License: rel.License,
ProvidesIncludes: rel.ProvidesIncludes,
Dependencies: getLibraryDependenciesParameter(rel.GetDependencies()),
Resources: &rpc.DownloadResource{
Url: rel.Resource.URL,
Archivefilename: rel.Resource.ArchiveFileName,
Expand All @@ -78,3 +82,14 @@ func GetLibraryParameters(rel *librariesindex.Release) *rpc.LibraryRelease {
},
}
}

func getLibraryDependenciesParameter(deps []semver.Dependency) []*rpc.LibraryDependency {
res := []*rpc.LibraryDependency{}
for _, dep := range deps {
res = append(res, &rpc.LibraryDependency{
Name: dep.GetName(),
VersionConstraint: dep.GetConstraint().String(),
})
}
return res
}
Loading