@@ -19,7 +19,6 @@ import (
19
19
"context"
20
20
"fmt"
21
21
"os"
22
- "sort"
23
22
"strings"
24
23
"time"
25
24
@@ -32,29 +31,30 @@ import (
32
31
"github.com/arduino/go-paths-helper"
33
32
"github.com/sirupsen/logrus"
34
33
"github.com/spf13/cobra"
35
- semver "go.bug.st/relaxed-semver"
36
34
)
37
35
38
36
func initSearchCommand () * cobra.Command {
39
- var namesOnly bool // if true outputs lib names only.
37
+ var namesOnly bool
38
+ var omitReleasesDetails bool
40
39
searchCommand := & cobra.Command {
41
40
Use : fmt .Sprintf ("search [%s]" , tr ("LIBRARY_NAME" )),
42
41
Short : tr ("Searches for one or more libraries data." ),
43
42
Long : tr ("Search for one or more libraries data (case insensitive search)." ),
44
43
Example : " " + os .Args [0 ] + " lib search audio" ,
45
44
Args : cobra .ArbitraryArgs ,
46
45
Run : func (cmd * cobra.Command , args []string ) {
47
- runSearchCommand (args , namesOnly )
46
+ runSearchCommand (args , namesOnly , omitReleasesDetails )
48
47
},
49
48
}
50
49
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)." ))
51
51
return searchCommand
52
52
}
53
53
54
54
// indexUpdateInterval specifies the time threshold over which indexes are updated
55
55
const indexUpdateInterval = 60 * time .Minute
56
56
57
- func runSearchCommand (args []string , namesOnly bool ) {
57
+ func runSearchCommand (args []string , namesOnly bool , omitReleasesDetails bool ) {
58
58
inst , status := instance .Create ()
59
59
logrus .Info ("Executing `arduino-cli lib search`" )
60
60
@@ -75,8 +75,9 @@ func runSearchCommand(args []string, namesOnly bool) {
75
75
instance .Init (inst )
76
76
77
77
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 ,
80
81
})
81
82
if err != nil {
82
83
feedback .Fatal (tr ("Error searching for Libraries: %v" , err ), feedback .ErrGeneric )
@@ -166,7 +167,7 @@ func (res result) String() string {
166
167
out .WriteString (fmt .Sprintf (" " + tr ("Category: %s" )+ "\n " , latest .Category ))
167
168
out .WriteString (fmt .Sprintf (" " + tr ("Architecture: %s" )+ "\n " , strings .Join (latest .Architectures , ", " )))
168
169
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 )))
170
171
if len (latest .ProvidesIncludes ) > 0 {
171
172
out .WriteString (fmt .Sprintf (" " + tr ("Provides includes: %s" )+ "\n " , strings .Join (latest .ProvidesIncludes , ", " )))
172
173
}
@@ -178,17 +179,6 @@ func (res result) String() string {
178
179
return out .String ()
179
180
}
180
181
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
-
192
182
// indexNeedsUpdating returns whether library_index.json needs updating
193
183
func indexNeedsUpdating (timeout time.Duration ) bool {
194
184
// Library index path is constant (relative to the data directory).
0 commit comments