Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 218e9c8

Browse files
Core and lib search command now update indexes first
1 parent a9c0a97 commit 218e9c8

File tree

4 files changed

+56
-40
lines changed

4 files changed

+56
-40
lines changed

‎cli/core/search.go‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,16 @@
1616
package core
1717

1818
import (
19+
"context"
1920
"os"
2021
"sort"
2122
"strings"
2223

2324
"github.com/arduino/arduino-cli/cli/errorcodes"
2425
"github.com/arduino/arduino-cli/cli/feedback"
2526
"github.com/arduino/arduino-cli/cli/instance"
27+
"github.com/arduino/arduino-cli/cli/output"
28+
"github.com/arduino/arduino-cli/commands"
2629
"github.com/arduino/arduino-cli/commands/core"
2730
rpc "github.com/arduino/arduino-cli/rpc/commands"
2831
"github.com/arduino/arduino-cli/table"
@@ -55,6 +58,14 @@ func runSearchCommand(cmd *cobra.Command, args []string) {
5558
os.Exit(errorcodes.ErrGeneric)
5659
}
5760

61+
_, err = commands.UpdateIndex(context.Background(), &rpc.UpdateIndexReq{
62+
Instance: inst,
63+
}, output.ProgressBar())
64+
if err != nil {
65+
feedback.Errorf("Error updating index: %v", err)
66+
os.Exit(errorcodes.ErrGeneric)
67+
}
68+
5869
arguments := strings.ToLower(strings.Join(args, " "))
5970
logrus.Infof("Executing `arduino core search` with args: '%s'", arguments)
6071

‎cli/lib/search.go‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ import (
2525
"github.com/arduino/arduino-cli/cli/errorcodes"
2626
"github.com/arduino/arduino-cli/cli/feedback"
2727
"github.com/arduino/arduino-cli/cli/instance"
28+
"github.com/arduino/arduino-cli/cli/output"
29+
"github.com/arduino/arduino-cli/commands"
2830
"github.com/arduino/arduino-cli/commands/lib"
2931
rpc "github.com/arduino/arduino-cli/rpc/commands"
3032
"github.com/sirupsen/logrus"
@@ -51,6 +53,15 @@ var searchFlags struct {
5153

5254
func runSearchCommand(cmd *cobra.Command, args []string) {
5355
instance := instance.CreateInstanceIgnorePlatformIndexErrors()
56+
57+
err := commands.UpdateLibrariesIndex(context.Background(), &rpc.UpdateLibrariesIndexReq{
58+
Instance: instance,
59+
}, output.ProgressBar())
60+
if err != nil {
61+
feedback.Errorf("Error updating library index: %v", err)
62+
os.Exit(errorcodes.ErrGeneric)
63+
}
64+
5465
logrus.Info("Executing `arduino lib search`")
5566
searchResp, err := lib.LibrarySearch(context.Background(), &rpc.LibrarySearchReq{
5667
Instance: instance,

‎test/test_core.py‎

Lines changed: 31 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -48,32 +48,39 @@ def test_core_search(run_command, httpserver):
4848
# Search all Retrokit platforms
4949
result = run_command(f"core search retrokit --all --additional-urls={url}")
5050
assert result.ok
51-
assert 3 == len(result.stdout.strip().splitlines())
52-
lines = [l.split(maxsplit=2) for l in result.stdout.strip().splitlines()]
51+
lines = [l.strip().split() for l in result.stdout.strip().splitlines()]
52+
assert 11 == len(lines)
53+
assert ["Updating", "index:", "package_index.json", "downloaded"] in lines
54+
assert ["Updating", "index:", "package_index.json.sig", "downloaded"] in lines
5355
assert ["Retrokits-RK002:arm", "1.0.5", "RK002"] in lines
5456
assert ["Retrokits-RK002:arm", "1.0.6", "RK002"] in lines
5557

5658
# Search using Retrokit Package Maintainer
5759
result = run_command(f"core search Retrokits-RK002 --all --additional-urls={url}")
5860
assert result.ok
59-
assert 3 == len(result.stdout.strip().splitlines())
60-
lines = [l.split(maxsplit=2) for l in result.stdout.strip().splitlines()]
61+
lines = [l.strip().split() for l in result.stdout.strip().splitlines()]
62+
assert 11 == len(lines)
63+
assert ["Updating", "index:", "package_index.json", "downloaded"] in lines
64+
assert ["Updating", "index:", "package_index.json.sig", "downloaded"] in lines
6165
assert ["Retrokits-RK002:arm", "1.0.5", "RK002"] in lines
6266
assert ["Retrokits-RK002:arm", "1.0.6", "RK002"] in lines
6367

6468
# Search using the Retrokit Platform name
6569
result = run_command(f"core search rk002 --all --additional-urls={url}")
6670
assert result.ok
67-
assert 3 == len(result.stdout.strip().splitlines())
68-
lines = [l.split(maxsplit=2) for l in result.stdout.strip().splitlines()]
71+
assert 11 == len(lines)
72+
assert ["Updating", "index:", "package_index.json", "downloaded"] in lines
73+
assert ["Updating", "index:", "package_index.json.sig", "downloaded"] in lines
6974
assert ["Retrokits-RK002:arm", "1.0.5", "RK002"] in lines
7075
assert ["Retrokits-RK002:arm", "1.0.6", "RK002"] in lines
7176

7277
# Search using a board name
7378
result = run_command(f"core search myboard --all --additional-urls={url}")
7479
assert result.ok
75-
assert 2 == len(result.stdout.strip().splitlines())
76-
lines = [l.split(maxsplit=2) for l in result.stdout.strip().splitlines()]
80+
assert 10 == len(result.stdout.strip().splitlines())
81+
lines = [l.strip().split() for l in result.stdout.strip().splitlines()]
82+
assert ["Updating", "index:", "package_index.json", "downloaded"] in lines
83+
assert ["Updating", "index:", "package_index.json.sig", "downloaded"] in lines
7784
assert ["Package:x86", "1.2.3", "Platform"] in lines
7885

7986

@@ -95,48 +102,38 @@ def test_core_search_no_args(run_command, httpserver):
95102
result = run_command("core search")
96103
assert result.ok
97104
num_platforms = 0
98-
found = False
99-
for l in result.stdout.splitlines()[1:]: # ignore the header on first line
100-
if l: # ignore empty lines
101-
if l.startswith("test:x86"):
102-
found = True
103-
num_platforms += 1
105+
lines = [l.strip().split() for l in result.stdout.strip().splitlines()]
106+
# Index update output and the header are printed on the first lines
107+
assert ["Updating", "index:", "package_index.json", "downloaded"] in lines[:6]
108+
assert ["Updating", "index:", "package_index.json.sig", "downloaded"] in lines[:6]
109+
assert ["ID", "Version", "Name"] == lines[5]
110+
assert ["test:x86", "2.0.0", "test_core"] in lines[6:]
111+
num_platforms = len(lines[6:])
104112

105113
# same thing in JSON format, also check the number of platforms found is the same
106114
result = run_command("core search --format json")
107115
assert result.ok
108116
platforms = json.loads(result.stdout)
109-
found = False
110-
platforms = json.loads(result.stdout)
111-
for elem in platforms:
112-
if elem.get("Name") == "test_core":
113-
found = True
114-
break
115-
assert found
117+
assert 1 == len([e for e in platforms if e.get("Name") == "test_core"])
116118
assert len(platforms) == num_platforms
117119

118120
# list all with additional urls, check the test core is there
119121
result = run_command(f"core search --additional-urls={url}")
120122
assert result.ok
121123
num_platforms = 0
122-
found = False
123-
forlinresult.stdout.splitlines()[1:]: # ignore the header on first line
124-
ifl: # ignore empty lines
125-
ifl.startswith("test:x86"):
126-
found=True
127-
num_platforms+=1
128-
assertfound
124+
lines = [l.strip().split() forlinresult.stdout.strip().splitlines()]
125+
# Index update output and the header are printed on the first lines
126+
assert ["Updating", "index:", "package_index.json", "downloaded"] inlines[:9]
127+
assert ["Updating", "index:", "package_index.json.sig", "downloaded"] inlines[:9]
128+
assert ["ID", "Version", "Name"] ==lines[8]
129+
assert ["test:x86", "2.0.0", "test_core"] inlines[9:]
130+
num_platforms=len(lines[9:])
129131

130132
# same thing in JSON format, also check the number of platforms found is the same
131133
result = run_command(f"core search --format json --additional-urls={url}")
132134
assert result.ok
133-
found = False
134135
platforms = json.loads(result.stdout)
135-
for elem in platforms:
136-
if elem.get("Name") == "test_core":
137-
found = True
138-
break
139-
assert found
136+
assert 1 == len([e for e in platforms if e.get("Name") == "test_core"])
140137
assert len(platforms) == num_platforms
141138

142139

‎test/test_lib.py‎

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -204,12 +204,9 @@ def test_search(run_command):
204204

205205
result = run_command("lib search --names")
206206
assert result.ok
207-
out_lines = result.stdout.strip().splitlines()
208-
# Create an array with just the name of the vars
209-
libs = []
210-
for line in out_lines:
211-
start = line.find('"') + 1
212-
libs.append(line[start:-1])
207+
lines = [l.strip() for l in result.stdout.strip().splitlines()]
208+
assert "Updating index: library_index.json downloaded" in lines
209+
libs = [l[6:].strip('"') for l in lines[3:]]
213210

214211
expected = {"WiFi101", "WiFi101OTA", "Firebase Arduino based on WiFi101"}
215212
assert expected == {lib for lib in libs if "WiFi101" in lib}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /