Unverified Commit 4b874a02 authored by Cristian Maglie's avatar Cristian Maglie Committed by GitHub

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

* Added 'license' and 'provides_includes' fields in lib search

* Added 'dependencies' field in lib search

* Do not output empty field in 'lib search'

Fields 'license', 'provided includes' and 'dependencies' are printed
only if populated.
parent 561618a4
...@@ -41,17 +41,19 @@ type Library struct { ...@@ -41,17 +41,19 @@ type Library struct {
// Release is a release of a library available for download // Release is a release of a library available for download
type Release struct { type Release struct {
Author string Author string
Version *semver.Version Version *semver.Version
Dependencies []semver.Dependency Dependencies []semver.Dependency
Maintainer string Maintainer string
Sentence string Sentence string
Paragraph string Paragraph string
Website string Website string
Category string Category string
Architectures []string Architectures []string
Types []string Types []string
Resource *resources.DownloadResource Resource *resources.DownloadResource
License string
ProvidesIncludes []string
Library *Library `json:"-"` Library *Library `json:"-"`
} }
......
...@@ -29,21 +29,23 @@ type indexJSON struct { ...@@ -29,21 +29,23 @@ type indexJSON struct {
} }
type indexRelease struct { type indexRelease struct {
Name string `json:"name,required"` Name string `json:"name,required"`
Version *semver.Version `json:"version,required"` Version *semver.Version `json:"version,required"`
Author string `json:"author"` Author string `json:"author"`
Maintainer string `json:"maintainer"` Maintainer string `json:"maintainer"`
Sentence string `json:"sentence"` Sentence string `json:"sentence"`
Paragraph string `json:"paragraph"` Paragraph string `json:"paragraph"`
Website string `json:"website"` Website string `json:"website"`
Category string `json:"category"` Category string `json:"category"`
Architectures []string `json:"architectures"` Architectures []string `json:"architectures"`
Types []string `json:"types"` Types []string `json:"types"`
URL string `json:"url"` URL string `json:"url"`
ArchiveFileName string `json:"archiveFileName"` ArchiveFileName string `json:"archiveFileName"`
Size int64 `json:"size"` Size int64 `json:"size"`
Checksum string `json:"checksum"` Checksum string `json:"checksum"`
Dependencies []*indexDependency `json:"dependencies,omitempty"` Dependencies []*indexDependency `json:"dependencies,omitempty"`
License string `json:"license"`
ProvidesIncludes []string `json:"providesIncludes"`
} }
type indexDependency struct { type indexDependency struct {
...@@ -107,8 +109,10 @@ func (indexLib *indexRelease) extractReleaseIn(library *Library) { ...@@ -107,8 +109,10 @@ func (indexLib *indexRelease) extractReleaseIn(library *Library) {
Checksum: indexLib.Checksum, Checksum: indexLib.Checksum,
CachePath: "libraries", CachePath: "libraries",
}, },
Library: library, Library: library,
Dependencies: indexLib.extractDependencies(), Dependencies: indexLib.extractDependencies(),
License: indexLib.License,
ProvidesIncludes: indexLib.ProvidesIncludes,
} }
library.Releases[indexLib.Version.String()] = release library.Releases[indexLib.Version.String()] = release
if library.Latest == nil || library.Latest.Version.LessThan(release.Version) { if library.Latest == nil || library.Latest.Version.LessThan(release.Version) {
......
...@@ -113,21 +113,41 @@ func (res result) String() string { ...@@ -113,21 +113,41 @@ func (res result) String() string {
var out strings.Builder var out strings.Builder
for _, lsr := range results { for _, lib := range results {
out.WriteString(fmt.Sprintf("Name: \"%s\"\n", lsr.Name)) out.WriteString(fmt.Sprintf("Name: \"%s\"\n", lib.Name))
if res.namesOnly { if res.namesOnly {
continue continue
} }
out.WriteString(fmt.Sprintf(" Author: %s\n", lsr.GetLatest().Author)) latest := lib.GetLatest()
out.WriteString(fmt.Sprintf(" Maintainer: %s\n", lsr.GetLatest().Maintainer))
out.WriteString(fmt.Sprintf(" Sentence: %s\n", lsr.GetLatest().Sentence)) deps := []string{}
out.WriteString(fmt.Sprintf(" Paragraph: %s\n", lsr.GetLatest().Paragraph)) for _, dep := range latest.GetDependencies() {
out.WriteString(fmt.Sprintf(" Website: %s\n", lsr.GetLatest().Website)) if dep.GetVersionConstraint() == "" {
out.WriteString(fmt.Sprintf(" Category: %s\n", lsr.GetLatest().Category)) deps = append(deps, dep.GetName())
out.WriteString(fmt.Sprintf(" Architecture: %s\n", strings.Join(lsr.GetLatest().Architectures, ", "))) } else {
out.WriteString(fmt.Sprintf(" Types: %s\n", strings.Join(lsr.GetLatest().Types, ", "))) deps = append(deps, dep.GetName()+" ("+dep.GetVersionConstraint()+")")
out.WriteString(fmt.Sprintf(" Versions: %s\n", strings.Replace(fmt.Sprint(versionsFromSearchedLibrary(lsr)), " ", ", ", -1))) }
}
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()) return fmt.Sprintf("%s", out.String())
......
...@@ -23,6 +23,7 @@ import ( ...@@ -23,6 +23,7 @@ import (
"github.com/arduino/arduino-cli/arduino/libraries/librariesindex" "github.com/arduino/arduino-cli/arduino/libraries/librariesindex"
"github.com/arduino/arduino-cli/commands" "github.com/arduino/arduino-cli/commands"
rpc "github.com/arduino/arduino-cli/rpc/commands" rpc "github.com/arduino/arduino-cli/rpc/commands"
semver "go.bug.st/relaxed-semver"
) )
// LibrarySearch FIXMEDOC // LibrarySearch FIXMEDOC
...@@ -60,15 +61,18 @@ func LibrarySearch(ctx context.Context, req *rpc.LibrarySearchReq) (*rpc.Library ...@@ -60,15 +61,18 @@ func LibrarySearch(ctx context.Context, req *rpc.LibrarySearchReq) (*rpc.Library
// GetLibraryParameters FIXMEDOC // GetLibraryParameters FIXMEDOC
func GetLibraryParameters(rel *librariesindex.Release) *rpc.LibraryRelease { func GetLibraryParameters(rel *librariesindex.Release) *rpc.LibraryRelease {
return &rpc.LibraryRelease{ return &rpc.LibraryRelease{
Author: rel.Author, Author: rel.Author,
Version: rel.Version.String(), Version: rel.Version.String(),
Maintainer: rel.Maintainer, Maintainer: rel.Maintainer,
Sentence: rel.Sentence, Sentence: rel.Sentence,
Paragraph: rel.Paragraph, Paragraph: rel.Paragraph,
Website: rel.Website, Website: rel.Website,
Category: rel.Category, Category: rel.Category,
Architectures: rel.Architectures, Architectures: rel.Architectures,
Types: rel.Types, Types: rel.Types,
License: rel.License,
ProvidesIncludes: rel.ProvidesIncludes,
Dependencies: getLibraryDependenciesParameter(rel.GetDependencies()),
Resources: &rpc.DownloadResource{ Resources: &rpc.DownloadResource{
Url: rel.Resource.URL, Url: rel.Resource.URL,
Archivefilename: rel.Resource.ArchiveFileName, Archivefilename: rel.Resource.ArchiveFileName,
...@@ -78,3 +82,14 @@ func GetLibraryParameters(rel *librariesindex.Release) *rpc.LibraryRelease { ...@@ -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
}
This diff is collapsed.
...@@ -103,6 +103,14 @@ message LibraryRelease { ...@@ -103,6 +103,14 @@ message LibraryRelease {
repeated string architectures = 8; repeated string architectures = 8;
repeated string types = 9; repeated string types = 9;
DownloadResource resources = 10; DownloadResource resources = 10;
string license = 11;
repeated string provides_includes = 12;
repeated LibraryDependency dependencies = 13;
}
message LibraryDependency {
string name = 1;
string version_constraint = 2;
} }
message DownloadResource { message DownloadResource {
......
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