aboutsummaryrefslogtreecommitdiffstats
path: root/doc/gen_docs.go
blob: 83997488f67c20403d5077a1cedbc2a77170e2c2 (plain) (blame)
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
package main

import (
	"fmt"
	"os"
	"path"
	"path/filepath"
	"time"

	"github.com/spf13/cobra/doc"

	"github.com/MichaelMure/git-bug/commands"
)

func main() {
	fmt.Println("Generating documentation ...")

	tasks := map[string]func() error{
		"ManPage":  genManPage,
		"Markdown": genMarkdown,
	}

	// Due to concurrency issues in cobra, the following can't be concurrent :(

	// var wg sync.WaitGroup
	for name, f := range tasks {
		// wg.Add(1)
		// go func(name string, f func() error) {
		// 	defer wg.Done()
		err := f()
		if err != nil {
			fmt.Printf("  - %s: %v\n", name, err)
			return
		}
		fmt.Printf("  - %s: ok\n", name)
		// }(name, f)
	}

	// wg.Wait()
}

func genManPage() error {
	cwd, _ := os.Getwd()
	dir := path.Join(cwd, "doc", "man")

	date := time.Date(2019, 4, 1, 12, 0, 0, 0, time.UTC)

	header := &doc.GenManHeader{
		Title:   "GIT-BUG",
		Section: "1",
		Date:    &date,
		Source:  "Generated from git-bug's source code",
	}

	files, err := filepath.Glob(dir + "/*.1")
	if err != nil {
		return err
	}
	for _, f := range files {
		if err := os.Remove(f); err != nil {
			return err
		}
	}

	return doc.GenManTree(commands.NewRootCommand(), header, dir)
}

func genMarkdown() error {
	cwd, _ := os.Getwd()
	dir := path.Join(cwd, "doc", "md")

	files, err := filepath.Glob(dir + "/*.md")
	if err != nil {
		return err
	}
	for _, f := range files {
		if err := os.Remove(f); err != nil {
			return err
		}
	}

	return doc.GenMarkdownTree(commands.NewRootCommand(), dir)
}