Skip to content

Commit a23a0ca

Browse files
committed
use uniq slice of tools
1 parent f79f249 commit a23a0ca

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

pkg/makefile/make.go

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ var (
2020
)
2121

2222
func Generate(client *resty.Client, writer io.Writer, makefile string, toolsFile string, tools ...string) error {
23-
argTools, toolData := mergeWithToolsGo(toolsFile, tools)
23+
argTools, toolData := mergeWithToolsGo(toolsFile, unique(tools))
2424
return generate(client, writer, makefile, argTools, toolData)
2525
}
2626

@@ -155,3 +155,18 @@ func mergeWithToolsGo(fileName string, inTools []string) ([]string, []toolData)
155155

156156
return argTools, goTools
157157
}
158+
159+
func unique(slice []string) []string {
160+
// create a map with all the values as key
161+
uniqMap := make(map[string]struct{})
162+
for _, v := range slice {
163+
uniqMap[v] = struct{}{}
164+
}
165+
166+
// turn the map keys into a slice
167+
uniqSlice := make([]string, 0, len(uniqMap))
168+
for v := range uniqMap {
169+
uniqSlice = append(uniqSlice, v)
170+
}
171+
return uniqSlice
172+
}

0 commit comments

Comments
 (0)