-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathgenerate.go
53 lines (46 loc) · 1.13 KB
/
generate.go
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
52
53
package main
import (
"fmt"
"log"
"os"
"os/exec"
"path/filepath"
"strings"
"github.com/stackitcloud/stackit-cli/internal/cmd"
"github.com/spf13/cobra/doc"
)
const (
DocsFolder = "docs"
)
func main() {
repoRoot, err := getGitRepoRoot()
if err != nil {
log.Fatalf("Error determining Git repository root: %v", err)
}
docsDir := filepath.Join(repoRoot, DocsFolder)
err = os.RemoveAll(docsDir)
if err != nil {
log.Fatalf("Error removing old documentation directory: %v", err)
}
err = os.Mkdir(docsDir, os.ModePerm)
if err != nil {
log.Fatalf("Error creating new documentation directory: %v", err)
}
filePrepender := func(filename string) string {
return ""
}
linkHandler := func(filename string) string {
return fmt.Sprintf("./%s", filename)
}
err = doc.GenMarkdownTreeCustom(cmd.NewRootCmd("", "", nil), docsDir, filePrepender, linkHandler)
if err != nil {
log.Fatalf("Error generating documentation: %v", err)
}
}
func getGitRepoRoot() (string, error) {
output, err := exec.Command("git", "rev-parse", "--show-toplevel").Output()
if err != nil {
return "", err
}
return strings.TrimSpace(string(output)), nil
}