/
helper.go
47 lines (40 loc) · 1.06 KB
/
helper.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
package generator
import (
"fmt"
"io"
"os"
"strings"
)
func readAndAdjustTemplate(docFile io.ReadCloser) string {
//read template content
content, err := io.ReadAll(docFile)
checkError(err)
contentStr := string(content)
//replace old placeholder with new ones
contentStr = strings.ReplaceAll(contentStr, "# ${docGenStepName}", "{{StepName .}}")
contentStr = strings.ReplaceAll(contentStr, "## ${docGenDescription}", "{{Description .}}")
contentStr = strings.ReplaceAll(contentStr, "## ${docGenParameters}", "{{Parameters .}}")
contentStr = strings.ReplaceAll(contentStr, "## ${docGenConfiguration}", "")
contentStr = strings.ReplaceAll(contentStr, "## ${docJenkinsPluginDependencies}", "")
return contentStr
}
func checkError(err error) {
if err != nil {
fmt.Printf("Error occurred: %v\n", err)
os.Exit(1)
}
}
func contains(v []string, s string) bool {
for _, i := range v {
if i == s {
return true
}
}
return false
}
func ifThenElse(condition bool, positive string, negative string) string {
if condition {
return positive
}
return negative
}