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 {
// 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:"-"`
}
......
......@@ -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 {
......@@ -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) {
......
......@@ -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())
......
......@@ -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
......@@ -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,
......@@ -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 {
repeated string architectures = 8;
repeated string types = 9;
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 {
......
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