-
Notifications
You must be signed in to change notification settings - Fork 371
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
cmd: make krew search work with multiple indexes #574
Conversation
/hold |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some small nits. But overall this is great work.
/approve
cmd/krew/cmd/search.go
Outdated
keys := func(v map[string]pluginEntry) []string { | ||
out := make([]string, 0, len(v)) | ||
for k := range v { | ||
out = append(out, k) | ||
} | ||
return out | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's only a single use of this lambda. Have you considered inlining it?
A proper function would also make sense because this does not capture any variables.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will do
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
cmd/krew/cmd/search.go
Outdated
var status string | ||
if _, ok := installed[name]; ok { | ||
if index := installed[v.p.Name]; index == v.indexName { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a slight abuse of map[string]string
for a map of a pair of properties. Iow, instead of {"plugin": "index"}
we should have {"index/plugin": true}
.
You already do this for pluginMap
, why not for installed
too?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, that'd work to let me refactor.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
cmd/krew/cmd/search.go
Outdated
return nil | ||
} | ||
|
||
var rows [][]string | ||
cols := []string{"NAME", "DESCRIPTION", "INSTALLED"} | ||
for _, name := range matchNames { | ||
plugin := pluginMap[name] | ||
for _, name := range searchResults { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for _, name := range searchResults { | |
for _, canonicalName := range searchResults { |
would make it clearer that this name includes the index.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
@@ -46,3 +50,52 @@ func TestKrewSearchOne(t *testing.T) { | |||
t.Errorf("The first match should be krew") | |||
} | |||
} | |||
|
|||
func TestKrewSearchMultiIndex(t *testing.T) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice tests!
Mostly just refactoring. Added test to make sure search output is alphabetically sorted (even in case of multiple indexes). Signed-off-by: Ahmet Alp Balkan <[email protected]>
Signed-off-by: Ahmet Alp Balkan <[email protected]>
Signed-off-by: Ahmet Alp Balkan <[email protected]>
Nice work! |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: ahmetb, corneliusweig The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
Mostly just refactoring. Added test to make sure search output is
alphabetically sorted (even in case of multiple indexes).
Related issue: #566, #483
/assign @chriskim06
/assign @corneliusweig
/area multi-index