BuildpacksOutputRegex takes a BuildpackFields struct and returns a regex matching a line in the output of 'cf buildpacks' representing the given buildpack.
(fields BuildpackFields)
| 9 | // matching a line in the output of 'cf buildpacks' representing the given |
| 10 | // buildpack. |
| 11 | func BuildpacksOutputRegex(fields BuildpackFields) string { |
| 12 | anyStringRegex := `\S+` |
| 13 | optionalStringRegex := `\S*` |
| 14 | anyBoolRegex := `(true|false)` |
| 15 | anyIntRegex := `\d+` |
| 16 | |
| 17 | nameRegex := anyStringRegex |
| 18 | if fields.Name != "" { |
| 19 | nameRegex = regexp.QuoteMeta(fields.Name) |
| 20 | } |
| 21 | |
| 22 | positionRegex := anyIntRegex |
| 23 | if fields.Position != "" { |
| 24 | positionRegex = regexp.QuoteMeta(fields.Position) |
| 25 | } |
| 26 | |
| 27 | enabledRegex := anyBoolRegex |
| 28 | if fields.Enabled != "" { |
| 29 | enabledRegex = regexp.QuoteMeta(fields.Enabled) |
| 30 | } |
| 31 | |
| 32 | lockedRegex := anyBoolRegex |
| 33 | if fields.Locked != "" { |
| 34 | lockedRegex = regexp.QuoteMeta(fields.Locked) |
| 35 | } |
| 36 | |
| 37 | filenameRegex := anyStringRegex |
| 38 | if fields.Filename != "" { |
| 39 | filenameRegex = regexp.QuoteMeta(fields.Filename) |
| 40 | } |
| 41 | |
| 42 | stackRegex := optionalStringRegex |
| 43 | if fields.Stack != "" { |
| 44 | stackRegex = regexp.QuoteMeta(fields.Stack) |
| 45 | } |
| 46 | |
| 47 | return fmt.Sprintf(`%s\s+%s\s+%s\s+%s\s+%s\s+%s`, |
| 48 | positionRegex, |
| 49 | nameRegex, |
| 50 | stackRegex, |
| 51 | enabledRegex, |
| 52 | lockedRegex, |
| 53 | filenameRegex, |
| 54 | ) |
| 55 | } |
no outgoing calls
no test coverage detected