Skip to content

Commit fd33bd3

Browse files
committed
Move contains to utils
This will be needed in the Artifactory storage impl.
1 parent f623543 commit fd33bd3

File tree

3 files changed

+19
-10
lines changed

3 files changed

+19
-10
lines changed

cli/remove.go

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ func remove() *cobra.Command {
6969
}
7070

7171
versionCount := len(allVersions)
72-
if !all && version != "" && !contains(allVersions, version) {
72+
if !all && version != "" && !util.Contains(allVersions, version) {
7373
return xerrors.Errorf("%s does not exist", id)
7474
} else if versionCount == 0 {
7575
return xerrors.Errorf("%s.%s has no versions to delete", publisher, name)
@@ -108,12 +108,3 @@ func remove() *cobra.Command {
108108

109109
return cmd
110110
}
111-
112-
func contains(a []string, b string) bool {
113-
for _, astr := range a {
114-
if astr == b {
115-
return true
116-
}
117-
}
118-
return false
119-
}

util/util.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,12 @@ func Plural(count int, singular, plural string) string {
1313
}
1414
return strconv.Itoa(count) + " " + plural
1515
}
16+
17+
func Contains(a []string, b string) bool {
18+
for _, astr := range a {
19+
if astr == b {
20+
return true
21+
}
22+
}
23+
return false
24+
}

util/util_test.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,12 @@ func TestPlural(t *testing.T) {
1919
require.Equal(t, "1 dependency", util.Plural(1, "dependency", "dependencies"))
2020
require.Equal(t, "2 dependencies", util.Plural(2, "dependency", "dependencies"))
2121
}
22+
23+
func TestContains(t *testing.T) {
24+
t.Parallel()
25+
26+
require.True(t, util.Contains([]string{"foo", "bar"}, "foo"))
27+
require.True(t, util.Contains([]string{"foo", "bar"}, "bar"))
28+
require.False(t, util.Contains([]string{"foo", "bar"}, "baz"))
29+
require.False(t, util.Contains([]string{"foo", "bar"}, "foobar"))
30+
}

0 commit comments

Comments
 (0)