Skip to content

Commit 0a3ac05

Browse files
committed
address code review feedback
Signed-off-by: Ahmet Alp Balkan <[email protected]>
1 parent 50f16a3 commit 0a3ac05

File tree

3 files changed

+18
-16
lines changed

3 files changed

+18
-16
lines changed

cmd/krew/cmd/index.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ import (
2828
"sigs.k8s.io/krew/pkg/constants"
2929
)
3030

31+
var (
32+
forceIndexDelete *bool
33+
)
34+
3135
// indexCmd represents the index command
3236
var indexCmd = &cobra.Command{
3337
Use: "index",
@@ -86,21 +90,21 @@ installed from them is not supported behavior.`,
8690
func indexDelete(_ *cobra.Command, args []string) error {
8791
name := args[0]
8892

89-
pl, err := installation.InstalledPluginsFromIndex(paths.InstallReceiptsPath(), name)
93+
ps, err := installation.InstalledPluginsFromIndex(paths.InstallReceiptsPath(), name)
9094
if err != nil {
9195
return errors.Wrap(err, "failed querying plugins installed from the index")
9296
}
93-
klog.V(4).Infof("Found %d plugins from index", len(pl))
97+
klog.V(4).Infof("Found %d plugins from index", len(ps))
9498

95-
if len(pl) > 0 && !*forceIndexDelete {
99+
if len(ps) > 0 && !*forceIndexDelete {
96100
var names []string
97-
for _, v := range pl {
98-
names = append(names, v.Name)
101+
for _, pl := range ps {
102+
names = append(names, pl.Name)
99103
}
100104

101105
internal.PrintWarning(os.Stderr, `Plugins [%s] are still installed from index %q.
102-
"Removing indexes while there are plugins installed from them may result in
103-
"unsupported behavior (use --force to ignore this check).`, strings.Join(names, ", "), name)
106+
Removing indexes while there are plugins installed from them may result in
107+
unsupported behavior (use --force to ignore this check).`, strings.Join(names, ", "), name)
104108
return errors.Errorf("there are still plugins installed from this index")
105109
}
106110

@@ -115,10 +119,6 @@ func indexDelete(_ *cobra.Command, args []string) error {
115119
return errors.Wrap(err, "error while removing the plugin index")
116120
}
117121

118-
var (
119-
forceIndexDelete *bool
120-
)
121-
122122
func init() {
123123
forceIndexDelete = indexDeleteCmd.Flags().Bool("force", false,
124124
"Remove index even if it has plugins currently installed (may result in unsupported behavior)")

integration_test/index_test.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ func TestKrewIndexList(t *testing.T) {
5858
t.Fatal("expected at least 1 index in output")
5959
}
6060

61-
test.Krew("index", "add", "foo", test.TempDir().Path("index/"+constants.DefaultIndexName)).RunOrFail()
61+
localIndex := test.TempDir().Path("index/" + constants.DefaultIndexName)
62+
test.Krew("index", "add", "foo", localIndex).RunOrFail()
6263
out = test.Krew("index", "list").RunOrFailOutput()
6364
if indexes := lines(out); len(indexes) < 3 {
6465
// the first line is the header
@@ -100,10 +101,11 @@ func TestKrewIndexRemove_nonExisting(t *testing.T) {
100101
func TestKrewIndexRemove_ok(t *testing.T) {
101102
skipShort(t)
102103
test, cleanup := NewTest(t)
103-
test = test.WithEnv(constants.EnableMultiIndexSwitch, 1)
104+
test = test.WithEnv(constants.EnableMultiIndexSwitch, 1).WithIndex()
104105
defer cleanup()
105106

106-
test.Krew("index", "add", "foo", constants.IndexURI).RunOrFail()
107+
localIndex := test.TempDir().Path("index/" + constants.DefaultIndexName)
108+
test.Krew("index", "add", "foo", localIndex).RunOrFail()
107109
test.Krew("index", "remove", "foo").RunOrFail()
108110
}
109111

@@ -114,7 +116,7 @@ func TestKrewIndexRemoveFailsWhenPluginsInstalled(t *testing.T) {
114116
defer cleanup()
115117

116118
test.Krew("install", validPlugin).RunOrFailOutput()
117-
if err := test.Krew("remove", "default").Run(); err == nil {
119+
if err := test.Krew("index", "remove", "default").Run(); err == nil {
118120
t.Fatal("expected error while removing index when there are installed plugins")
119121
}
120122

internal/index/indexoperations/index.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ type Index struct {
3838
func ListIndexes(paths environment.Paths) ([]Index, error) {
3939
dirs, err := ioutil.ReadDir(paths.IndexBase())
4040
if err != nil {
41-
return nil, errors.New("failed to list directory")
41+
return nil, errors.Wrap(err, "failed to list directory")
4242
}
4343

4444
indexes := []Index{}

0 commit comments

Comments
 (0)