Skip to content

Commit c6afede

Browse files
Use the same property name for the query term in search requests (#2214)
* Deprecate `query` in favor of `search_args` * Give priority to `search_args` if possible
1 parent 5725c02 commit c6afede

File tree

8 files changed

+271
-252
lines changed

8 files changed

+271
-252
lines changed

Diff for: client_example/main.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -881,8 +881,8 @@ func callLibUpgradeAll(client rpc.ArduinoCoreServiceClient, instance *rpc.Instan
881881
func callLibSearch(client rpc.ArduinoCoreServiceClient, instance *rpc.Instance) {
882882
libSearchResp, err := client.LibrarySearch(context.Background(),
883883
&rpc.LibrarySearchRequest{
884-
Instance: instance,
885-
Query: "audio",
884+
Instance: instance,
885+
SearchArgs: "audio",
886886
})
887887

888888
if err != nil {

Diff for: commands/lib/search.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,10 @@ func LibrarySearch(ctx context.Context, req *rpc.LibrarySearchRequest) (*rpc.Lib
4040

4141
func searchLibrary(req *rpc.LibrarySearchRequest, lm *librariesmanager.LibrariesManager) *rpc.LibrarySearchResponse {
4242
res := []*rpc.SearchedLibrary{}
43-
query := req.GetQuery()
43+
query := req.GetSearchArgs()
44+
if query == "" {
45+
query = req.GetQuery()
46+
}
4447
queryTerms := utils.SearchTermsFromQueryString(query)
4548

4649
for _, lib := range lm.Index.Libraries {

Diff for: commands/lib/search_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ func TestSearchLibrary(t *testing.T) {
3333
lm := librariesmanager.NewLibraryManager(customIndexPath, nil)
3434
lm.LoadIndex()
3535

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

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

6464
query := func(q string) []string {
6565
libs := []string{}
66-
for _, lib := range searchLibrary(&rpc.LibrarySearchRequest{Query: q}, lm).Libraries {
66+
for _, lib := range searchLibrary(&rpc.LibrarySearchRequest{SearchArgs: q}, lm).Libraries {
6767
libs = append(libs, lib.Name)
6868
}
6969
return libs

Diff for: internal/cli/arguments/completion.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -190,8 +190,8 @@ func GetInstallableLibs() []string {
190190
inst := instance.CreateAndInit()
191191

192192
libs, _ := lib.LibrarySearch(context.Background(), &rpc.LibrarySearchRequest{
193-
Instance: inst,
194-
Query: "", // if no query is specified all the libs are returned
193+
Instance: inst,
194+
SearchArgs: "", // if no query is specified all the libs are returned
195195
})
196196
var res []string
197197
// transform the data structure for the completion

Diff for: internal/cli/lib/args.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,8 @@ func ParseLibraryReferenceArgs(args []string) ([]*LibraryReferenceArg, error) {
7777
func ParseLibraryReferenceArgAndAdjustCase(instance *rpc.Instance, arg string) (*LibraryReferenceArg, error) {
7878
libRef, _ := ParseLibraryReferenceArg(arg)
7979
res, err := lib.LibrarySearch(context.Background(), &rpc.LibrarySearchRequest{
80-
Instance: instance,
81-
Query: libRef.Name,
80+
Instance: instance,
81+
SearchArgs: libRef.Name,
8282
})
8383
if err != nil {
8484
return nil, err

Diff for: internal/cli/lib/search.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ func runSearchCommand(args []string, namesOnly bool, omitReleasesDetails bool) {
7676

7777
searchResp, err := lib.LibrarySearch(context.Background(), &rpc.LibrarySearchRequest{
7878
Instance: inst,
79-
Query: strings.Join(args, " "),
79+
SearchArgs: strings.Join(args, " "),
8080
OmitReleasesDetails: omitReleasesDetails,
8181
})
8282
if err != nil {

Diff for: rpc/cc/arduino/cli/commands/v1/lib.pb.go

+253-239
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: rpc/cc/arduino/cli/commands/v1/lib.proto

+4-2
Original file line numberDiff line numberDiff line change
@@ -137,11 +137,13 @@ message LibraryDependencyStatus {
137137
message LibrarySearchRequest {
138138
// Arduino Core Service instance from the `Init` response.
139139
Instance instance = 1;
140-
// The search query.
141-
string query = 2;
140+
// Deprecated. Use search_args instead.
141+
string query = 2 [ deprecated = true ];
142142
// Set to true to not populate the releases field in the response (may save a
143143
// lot of bandwidth/CPU).
144144
bool omit_releases_details = 3;
145+
// Keywords for the search.
146+
string search_args = 4;
145147
}
146148

147149
enum LibrarySearchStatus {

0 commit comments

Comments
 (0)