Skip to content

Commit

Permalink
Added dependencies, license and provides_includes fields in 'lib sear…
Browse files Browse the repository at this point in the history
…ch' (#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.
  • Loading branch information
cmaglie committed Feb 28, 2020
1 parent 561618a commit 4b874a0
Show file tree
Hide file tree
Showing 6 changed files with 267 additions and 142 deletions.
24 changes: 13 additions & 11 deletions arduino/libraries/librariesindex/index.go
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
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
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
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
}

0 comments on commit 4b874a0

Please sign in to comment.