Skip to content

Commit 13764a5

Browse files
committed
removes blank lines that contains only “/“ just because it makes the script pretty :)
1 parent 0b54130 commit 13764a5

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

main.go

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"log"
88
"os"
99
"path"
10+
"regexp"
1011
"strings"
1112
"text/template"
1213

@@ -80,6 +81,21 @@ func setLinksWithAppName(service *Service) {
8081
}
8182
}
8283

84+
func removeBlankLinkes(path string) {
85+
re := regexp.MustCompile(`(?m)^\s*\\\n`)
86+
read, err := ioutil.ReadFile(path)
87+
if err != nil {
88+
panic(err)
89+
}
90+
91+
newContents := re.ReplaceAllString(string(read), "")
92+
93+
err = ioutil.WriteFile(path, []byte(newContents), 0)
94+
if err != nil {
95+
panic(err)
96+
}
97+
}
98+
8399
func buildScriptDataTemplate(serviceName string, service Service) ScriptDataTemplate {
84100
// common data template for all services from the same app
85101
data := ScriptDataTemplate{AppName: appName}
@@ -105,10 +121,13 @@ func saveToBash(services map[string]Service) (err error) {
105121

106122
for name, service := range services {
107123
data := buildScriptDataTemplate(name, service)
124+
fileName := path.Join(outputPath, data.Service.Name+".1.sh")
108125

109-
f, _ := os.Create(path.Join(outputPath, data.Service.Name+".1.sh"))
126+
f, _ := os.Create(fileName)
110127
defer f.Close()
111128
t.Execute(f, data)
129+
130+
removeBlankLinkes(fileName)
112131
}
113132

114133
return nil

0 commit comments

Comments
 (0)