git-bug/doc/gen_docs.go

85 lines
1.5 KiB
Go
Raw Normal View History

package main
import (
"fmt"
"os"
"path/filepath"
2020-09-27 22:30:50 +03:00
"sync"
"time"
2020-09-27 22:30:50 +03:00
"github.com/spf13/cobra"
"github.com/spf13/cobra/doc"
"github.com/MichaelMure/git-bug/commands"
)
func main() {
fmt.Println("Generating documentation ...")
2020-09-27 22:30:50 +03:00
tasks := map[string]func(*cobra.Command) error{
"ManPage": genManPage,
"Markdown": genMarkdown,
}
2020-09-27 22:30:50 +03:00
var wg sync.WaitGroup
for name, f := range tasks {
2020-09-27 22:30:50 +03:00
wg.Add(1)
go func(name string, f func(*cobra.Command) error) {
defer wg.Done()
root := commands.NewRootCommand()
err := f(root)
if err != nil {
fmt.Printf(" - %s: %v\n", name, err)
return
}
fmt.Printf(" - %s: ok\n", name)
}(name, f)
}
2020-09-27 22:30:50 +03:00
wg.Wait()
}
2020-09-27 22:30:50 +03:00
func genManPage(root *cobra.Command) error {
cwd, _ := os.Getwd()
2020-12-05 05:08:54 +03:00
dir := filepath.Join(cwd, "doc", "man")
2020-09-27 22:30:50 +03:00
// fixed date to avoid having to commit each month
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
}
}
2020-09-27 22:30:50 +03:00
return doc.GenManTree(root, header, dir)
}
2020-09-27 22:30:50 +03:00
func genMarkdown(root *cobra.Command) error {
cwd, _ := os.Getwd()
2020-12-05 05:08:54 +03:00
dir := filepath.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
}
}
2020-09-27 22:30:50 +03:00
return doc.GenMarkdownTree(root, dir)
}