summaryrefslogtreecommitdiff
path: root/man/man.go
diff options
context:
space:
mode:
authorewy <ewy0@protonmail.com>2026-06-01 18:47:44 +0200
committerewy <ewy0@protonmail.com>2026-06-01 18:47:44 +0200
commit46d032cd21b0e8e2c94a32333d3805ec76980cca (patch)
treefbb8aed5c5a501aca1309f62a9d4440ca949ce4c /man/man.go
parent7585a488b7b1e1812f7ebf50107139e2fd65f035 (diff)
add man(1) generation
Diffstat (limited to 'man/man.go')
-rw-r--r--man/man.go50
1 files changed, 50 insertions, 0 deletions
diff --git a/man/man.go b/man/man.go
new file mode 100644
index 0000000..49018ed
--- /dev/null
+++ b/man/man.go
@@ -0,0 +1,50 @@
+package main
+
+import (
+ "embed"
+ "github.com/ewy1/pik/spool"
+ "github.com/spf13/pflag"
+ "os"
+ "path/filepath"
+ "strings"
+ "text/template"
+)
+
+//go:embed 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, filepath.Join(templateDir, "*"))
+ 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 := 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)
+ }
+ }
+}