@@ -19,7 +19,6 @@ import (
1919 "context"
2020 "fmt"
2121 "os"
22- "sort"
2322 "strings"
2423 "time"
2524
@@ -32,29 +31,30 @@ import (
3231 "github.com/arduino/go-paths-helper"
3332 "github.com/sirupsen/logrus"
3433 "github.com/spf13/cobra"
35- semver "go.bug.st/relaxed-semver"
3634)
3735
3836func initSearchCommand () * cobra.Command {
39- var namesOnly bool // if true outputs lib names only.
37+ var namesOnly bool
38+ var omitReleasesDetails bool
4039 searchCommand := & cobra.Command {
4140 Use : fmt .Sprintf ("search [%s]" , tr ("LIBRARY_NAME" )),
4241 Short : tr ("Searches for one or more libraries data." ),
4342 Long : tr ("Search for one or more libraries data (case insensitive search)." ),
4443 Example : " " + os .Args [0 ] + " lib search audio" ,
4544 Args : cobra .ArbitraryArgs ,
4645 Run : func (cmd * cobra.Command , args []string ) {
47- runSearchCommand (args , namesOnly )
46+ runSearchCommand (args , namesOnly , omitReleasesDetails )
4847 },
4948 }
5049 searchCommand .Flags ().BoolVar (& namesOnly , "names" , false , tr ("Show library names only." ))
50+ searchCommand .Flags ().BoolVar (& omitReleasesDetails , "omit-releases-details" , false , tr ("Omit library details far all versions except the latest (produce a more compact JSON output)." ))
5151 return searchCommand
5252}
5353
5454// indexUpdateInterval specifies the time threshold over which indexes are updated
5555const indexUpdateInterval = 60 * time .Minute
5656
57- func runSearchCommand (args []string , namesOnly bool ) {
57+ func runSearchCommand (args []string , namesOnly bool , omitReleasesDetails bool ) {
5858 inst , status := instance .Create ()
5959 logrus .Info ("Executing `arduino-cli lib search`" )
6060
@@ -75,8 +75,9 @@ func runSearchCommand(args []string, namesOnly bool) {
7575 instance .Init (inst )
7676
7777 searchResp , err := lib .LibrarySearch (context .Background (), & rpc.LibrarySearchRequest {
78- Instance : inst ,
79- Query : strings .Join (args , " " ),
78+ Instance : inst ,
79+ Query : strings .Join (args , " " ),
80+ OmitReleasesDetails : omitReleasesDetails ,
8081 })
8182 if err != nil {
8283 feedback .Fatal (tr ("Error searching for Libraries: %v" , err ), feedback .ErrGeneric )
@@ -166,7 +167,7 @@ func (res result) String() string {
166167 out .WriteString (fmt .Sprintf (" " + tr ("Category: %s" )+ "\n " , latest .Category ))
167168 out .WriteString (fmt .Sprintf (" " + tr ("Architecture: %s" )+ "\n " , strings .Join (latest .Architectures , ", " )))
168169 out .WriteString (fmt .Sprintf (" " + tr ("Types: %s" )+ "\n " , strings .Join (latest .Types , ", " )))
169- out .WriteString (fmt .Sprintf (" " + tr ("Versions: %s" )+ "\n " , strings .Replace (fmt .Sprint (versionsFromSearchedLibrary ( lib )), " " , ", " , - 1 )))
170+ out .WriteString (fmt .Sprintf (" " + tr ("Versions: %s" )+ "\n " , strings .Replace (fmt .Sprint (lib . GetAvailableVersions ( )), " " , ", " , - 1 )))
170171 if len (latest .ProvidesIncludes ) > 0 {
171172 out .WriteString (fmt .Sprintf (" " + tr ("Provides includes: %s" )+ "\n " , strings .Join (latest .ProvidesIncludes , ", " )))
172173 }
@@ -178,17 +179,6 @@ func (res result) String() string {
178179 return out .String ()
179180}
180181
181- func versionsFromSearchedLibrary (library * rpc.SearchedLibrary ) []* semver.Version {
182- res := []* semver.Version {}
183- for str := range library .Releases {
184- if v , err := semver .Parse (str ); err == nil {
185- res = append (res , v )
186- }
187- }
188- sort .Sort (semver .List (res ))
189- return res
190- }
191-
192182// indexNeedsUpdating returns whether library_index.json needs updating
193183func indexNeedsUpdating (timeout time.Duration ) bool {
194184 // Library index path is constant (relative to the data directory).
0 commit comments