fuzzyworld

template / windows / files / postscript.go

Branch windows · default branch · all branches

postscript.go

Blame: the commit that last changed each line · file · history

c62570e2 2022-09-23 Pavel Safronov1package main
2
3import (
763c260d 2022-10-06 Pavel Safronov4 "fmt"
c62570e2 2022-09-23 Pavel Safronov5 "strings"
6 "text/template"
7)
8
687d5626 2022-10-28 Pavel Safronov9func createPostScriptArrays(
10 profile Profile,
11 postPatternData PostPatternData) ([]string, error) {
d1bc1307 2022-09-24 Pavel Safronov12 array := make([]string, 0)
c62570e2 2022-09-23 Pavel Safronov13
4a7759db 2022-09-24 Pavel Safronov14 if profile.PostScripts == nil || len(profile.PostScripts) == 0 {
763c260d 2022-10-06 Pavel Safronov15 return nil, fmt.Errorf("no post scripts specified")
c62570e2 2022-09-23 Pavel Safronov16 }
17
d1bc1307 2022-09-24 Pavel Safronov18 for _, postScriptPattern := range profile.PostScripts {
1a02ef4e 2022-10-21 Pavel Safronov19 template, err := template.New("postscript").Parse(string(postScriptPattern))
d1bc1307 2022-09-24 Pavel Safronov20 if err != nil {
21 return nil, err
22 }
c62570e2 2022-09-23 Pavel Safronov23
d1bc1307 2022-09-24 Pavel Safronov24 sb := new(strings.Builder)
687d5626 2022-10-28 Pavel Safronov25 err = template.Execute(sb, postPatternData)
d1bc1307 2022-09-24 Pavel Safronov26 if err != nil {
27 return nil, err
4a7759db 2022-09-24 Pavel Safronov28 }
d1bc1307 2022-09-24 Pavel Safronov29
30 postScript := sb.String()
31 array = append(array, postScript)
c62570e2 2022-09-23 Pavel Safronov32 }
33
34 return array, nil
35}