Skip to content

Commit

Permalink
Use the same property name for the query term in search requests (ard…
Browse files Browse the repository at this point in the history
…uino#2214)

* Deprecate `query` in favor of `search_args`

* Give priority to `search_args` if possible
  • Loading branch information
MatteoPologruto authored Jun 14, 2023
1 parent 5725c02 commit c6afede
Show file tree
Hide file tree
Showing 8 changed files with 271 additions and 252 deletions.
4 changes: 2 additions & 2 deletions client_example/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -881,8 +881,8 @@ func callLibUpgradeAll(client rpc.ArduinoCoreServiceClient, instance *rpc.Instan
func callLibSearch(client rpc.ArduinoCoreServiceClient, instance *rpc.Instance) {
libSearchResp, err := client.LibrarySearch(context.Background(),
&rpc.LibrarySearchRequest{
Instance: instance,
Query: "audio",
Instance: instance,
SearchArgs: "audio",
})

if err != nil {
Expand Down
5 changes: 4 additions & 1 deletion commands/lib/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@ func LibrarySearch(ctx context.Context, req *rpc.LibrarySearchRequest) (*rpc.Lib

func searchLibrary(req *rpc.LibrarySearchRequest, lm *librariesmanager.LibrariesManager) *rpc.LibrarySearchResponse {
res := []*rpc.SearchedLibrary{}
query := req.GetQuery()
query := req.GetSearchArgs()
if query == "" {
query = req.GetQuery()
}
queryTerms := utils.SearchTermsFromQueryString(query)

for _, lib := range lm.Index.Libraries {
Expand Down
6 changes: 3 additions & 3 deletions commands/lib/search_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func TestSearchLibrary(t *testing.T) {
lm := librariesmanager.NewLibraryManager(customIndexPath, nil)
lm.LoadIndex()

resp := searchLibrary(&rpc.LibrarySearchRequest{Query: "test"}, lm)
resp := searchLibrary(&rpc.LibrarySearchRequest{SearchArgs: "test"}, lm)
assert := assert.New(t)
assert.Equal(resp.GetStatus(), rpc.LibrarySearchStatus_LIBRARY_SEARCH_STATUS_SUCCESS)
assert.Equal(len(resp.GetLibraries()), 2)
Expand All @@ -45,7 +45,7 @@ func TestSearchLibrarySimilar(t *testing.T) {
lm := librariesmanager.NewLibraryManager(customIndexPath, nil)
lm.LoadIndex()

resp := searchLibrary(&rpc.LibrarySearchRequest{Query: "arduino"}, lm)
resp := searchLibrary(&rpc.LibrarySearchRequest{SearchArgs: "arduino"}, lm)
assert := assert.New(t)
assert.Equal(resp.GetStatus(), rpc.LibrarySearchStatus_LIBRARY_SEARCH_STATUS_SUCCESS)
assert.Equal(len(resp.GetLibraries()), 2)
Expand All @@ -63,7 +63,7 @@ func TestSearchLibraryFields(t *testing.T) {

query := func(q string) []string {
libs := []string{}
for _, lib := range searchLibrary(&rpc.LibrarySearchRequest{Query: q}, lm).Libraries {
for _, lib := range searchLibrary(&rpc.LibrarySearchRequest{SearchArgs: q}, lm).Libraries {
libs = append(libs, lib.Name)
}
return libs
Expand Down
4 changes: 2 additions & 2 deletions internal/cli/arguments/completion.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,8 @@ func GetInstallableLibs() []string {
inst := instance.CreateAndInit()

libs, _ := lib.LibrarySearch(context.Background(), &rpc.LibrarySearchRequest{
Instance: inst,
Query: "", // if no query is specified all the libs are returned
Instance: inst,
SearchArgs: "", // if no query is specified all the libs are returned
})
var res []string
// transform the data structure for the completion
Expand Down
4 changes: 2 additions & 2 deletions internal/cli/lib/args.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ func ParseLibraryReferenceArgs(args []string) ([]*LibraryReferenceArg, error) {
func ParseLibraryReferenceArgAndAdjustCase(instance *rpc.Instance, arg string) (*LibraryReferenceArg, error) {
libRef, _ := ParseLibraryReferenceArg(arg)
res, err := lib.LibrarySearch(context.Background(), &rpc.LibrarySearchRequest{
Instance: instance,
Query: libRef.Name,
Instance: instance,
SearchArgs: libRef.Name,
})
if err != nil {
return nil, err
Expand Down
2 changes: 1 addition & 1 deletion internal/cli/lib/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func runSearchCommand(args []string, namesOnly bool, omitReleasesDetails bool) {

searchResp, err := lib.LibrarySearch(context.Background(), &rpc.LibrarySearchRequest{
Instance: inst,
Query: strings.Join(args, " "),
SearchArgs: strings.Join(args, " "),
OmitReleasesDetails: omitReleasesDetails,
})
if err != nil {
Expand Down
492 changes: 253 additions & 239 deletions rpc/cc/arduino/cli/commands/v1/lib.pb.go

Large diffs are not rendered by default.

6 changes: 4 additions & 2 deletions rpc/cc/arduino/cli/commands/v1/lib.proto
Original file line number Diff line number Diff line change
Expand Up @@ -137,11 +137,13 @@ message LibraryDependencyStatus {
message LibrarySearchRequest {
// Arduino Core Service instance from the `Init` response.
Instance instance = 1;
// The search query.
string query = 2;
// Deprecated. Use search_args instead.
string query = 2 [ deprecated = true ];
// Set to true to not populate the releases field in the response (may save a
// lot of bandwidth/CPU).
bool omit_releases_details = 3;
// Keywords for the search.
string search_args = 4;
}

enum LibrarySearchStatus {
Expand Down

0 comments on commit c6afede

Please sign in to comment.