blob: 7f9c26ac6914180f9666c00c6b8e14c8842ddc15 (
plain)
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
|
// Copyright (C) 2024 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only
package generator
import (
"os"
"os/user"
"path/filepath"
"qtcli/util"
"text/template"
"time"
)
func generateLicense(
licenseTemplatePath string,
data util.StringAnyMap,
) (string, error) {
if len(licenseTemplatePath) == 0 {
return "", nil
}
now := time.Now()
user, _ := user.Current()
dataAll := util.StringAnyMap{
"Year": now.Format("2006"),
"Month": now.Format("01"),
"Day": now.Format("02"),
"Date": now.Format("2006-01-02"),
"User": user.Username,
}
dataAll.Merge(data)
return util.NewTemplateExpander().
Name(filepath.Base(licenseTemplatePath)).
Data(dataAll).
Funcs(template.FuncMap{
"qEnv": func(name string) string {
return os.Getenv(name)
},
}).
RunFile(licenseTemplatePath)
}
|