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
48
49
50
51
|
package main
import (
"embed"
"github.com/ewy1/pik/man/manview"
"github.com/ewy1/pik/spool"
"github.com/spf13/pflag"
"os"
"path/filepath"
"strings"
"text/template"
)
//go:embed manview/templates
var templates embed.FS
var ManOutput = pflag.String(manFlagName, "out", "directory to write man pages to (gets created)")
const manFlagName = "man-output"
const templateDir = "templates"
const manExtension = ".man"
const templateExtension = ".tmpl"
func main() {
pflag.Parse()
tmpl, err := template.ParseFS(templates, "*/*/*.tmpl")
if err != nil {
_, _ = spool.Panic(spool.ManFailure, "%v\n", err)
return
}
err = os.MkdirAll(*ManOutput, os.ModePerm)
if err != nil {
_, _ = spool.Panic(spool.ManFailure, "%v\n", err)
}
d := manview.NewData()
for _, t := range tmpl.Templates() {
if !strings.HasSuffix(t.Name(), manExtension+templateExtension) {
continue
}
resultFile, err := os.OpenFile(filepath.Join(*ManOutput, strings.TrimSuffix(strings.TrimSuffix(t.Name(), templateExtension), manExtension)), os.O_CREATE|os.O_WRONLY|os.O_TRUNC, 0600)
if err != nil {
_, _ = spool.Panic(spool.ManFailure, "%v\n", err)
}
err = t.Execute(resultFile, d)
if err != nil {
_, _ = spool.Panic(spool.ManFailure, "%v\n", err)
}
}
}
|