-
Notifications
You must be signed in to change notification settings - Fork 11
/
utils.go
63 lines (55 loc) · 1.41 KB
/
utils.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package main
import (
"fmt"
"log"
"strings"
shellwords "github.com/mattn/go-shellwords"
)
// isSliceInString - one of the elements of the array contained in the string
func isSliceInString(src string, slice []string) bool {
for _, dst := range slice {
if strings.Contains(src, dst) {
return true
}
}
return false
}
// isSliceInStringPrefix - one of the elements of the array is are prefix in the string
func isSliceInStringPrefix(src string, slice []string) bool {
for _, dst := range slice {
if strings.HasPrefix(src, dst) {
return true
}
}
return false
}
// grepEmptyStringSlice - return slice with non-empty strings
func grepEmptyStringSlice(inSlice []string) []string {
result := []string{}
for _, item := range inSlice {
if len(item) > 0 {
result = append(result, item)
}
}
return result
}
// parse additional args for pass to go test
func parseAdditionalArgs(argsRaw string, excludes []string) (resultArgs []string, err error) {
if argsRaw != "" {
args, err := shellwords.Parse(argsRaw)
if err != nil {
return resultArgs, fmt.Errorf("args %q parse failed: %s", argsRaw, err)
}
NEXTARG:
for _, arg := range args {
for _, excludeArg := range excludes {
if excludeArg != "" && strings.HasPrefix(arg, excludeArg) {
log.Printf("arg: %q is not allowed, skip", arg)
continue NEXTARG
}
}
resultArgs = append(resultArgs, arg)
}
}
return resultArgs, nil
}