forked from cloudfoundry/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
buildpack_v6.go
58 lines (48 loc) · 1.18 KB
/
buildpack_v6.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
// +build !V7
package helpers
import (
"fmt"
"regexp"
)
// BuildpacksOutputRegex takes a BuildpackFields struct and returns a regex
// matching a line in the output of 'cf buildpacks' representing the given
// buildpack.
func BuildpacksOutputRegex(fields BuildpackFields) string {
anyStringRegex := `\S+`
optionalStringRegex := `\S*`
anyBoolRegex := `(true|false)`
anyIntRegex := `\d+`
nameRegex := anyStringRegex
if fields.Name != "" {
nameRegex = regexp.QuoteMeta(fields.Name)
}
positionRegex := anyIntRegex
if fields.Position != "" {
positionRegex = regexp.QuoteMeta(fields.Position)
}
enabledRegex := anyBoolRegex
if fields.Enabled != "" {
enabledRegex = regexp.QuoteMeta(fields.Enabled)
}
lockedRegex := anyBoolRegex
if fields.Locked != "" {
lockedRegex = regexp.QuoteMeta(fields.Locked)
}
filenameRegex := anyStringRegex
if fields.Filename != "" {
filenameRegex = regexp.QuoteMeta(fields.Filename)
}
stackRegex := optionalStringRegex
if fields.Stack != "" {
stackRegex = regexp.QuoteMeta(fields.Stack)
}
return fmt.Sprintf(
`%s\s+%s\s+%s\s+%s\s+%s\s+%s`,
nameRegex,
positionRegex,
enabledRegex,
lockedRegex,
filenameRegex,
stackRegex,
)
}