diff options
| author | ewy <ewy0@protonmail.com> | 2026-06-01 19:37:34 +0200 |
|---|---|---|
| committer | ewy <ewy0@protonmail.com> | 2026-06-01 19:37:34 +0200 |
| commit | 3d46b9546e1ccf131ce4dbcbfc12f6e37fa301ea (patch) | |
| tree | 54bd9343fe51734b7e2377a844065f317bc51cc3 /man/view.go | |
| parent | 46d032cd21b0e8e2c94a32333d3805ec76980cca (diff) | |
default to manpage view for help
Diffstat (limited to 'man/view.go')
| -rw-r--r-- | man/view.go | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/man/view.go b/man/view.go new file mode 100644 index 0000000..bb4aac4 --- /dev/null +++ b/man/view.go @@ -0,0 +1,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) + } + } +} |
