-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathgenerate-docs.go
More file actions
47 lines (38 loc) · 1.02 KB
/
generate-docs.go
File metadata and controls
47 lines (38 loc) · 1.02 KB
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
// Copyright 2021 - 2026 Crunchy Data Solutions, Inc.
//
// SPDX-License-Identifier: Apache-2.0
//go:build docs
package main
import (
"log"
"os"
"path/filepath"
"strings"
"github.com/spf13/cobra/doc"
"sigs.k8s.io/yaml"
"github.com/crunchydata/postgres-operator-client/internal/cmd"
)
func main() {
filePrepender := func(filename string) string {
name := filepath.Base(filename)
base := strings.TrimSuffix(name, filepath.Ext(name))
command := strings.ReplaceAll(base, "_", " ")
// https://gohugo.io/content-management/front-matter/
front, _ := yaml.Marshal(map[string]any{
"title": command,
})
return "---\n" + string(front) + "---\n"
}
linkHandler := func(name string) string {
base := strings.TrimSuffix(name, filepath.Ext(name))
if base == "pgo" {
return "/reference/"
}
return "/reference/" + strings.ToLower(base) + "/"
}
pgo := cmd.NewPGOCommand(os.Stdin, os.Stdout, os.Stderr)
err := doc.GenMarkdownTreeCustom(pgo, "./", filePrepender, linkHandler)
if err != nil {
log.Fatal(err)
}
}