diff options
author | Michael Muré <batolettre@gmail.com> | 2020-09-27 21:30:50 +0200 |
---|---|---|
committer | Michael Muré <batolettre@gmail.com> | 2020-09-27 21:30:50 +0200 |
commit | 7f87eb8602b76acbf3acc91391249d0e76424db6 (patch) | |
tree | e473838db617dd8f1caed7271cb418dbcabbd652 /doc/gen_docs.go | |
parent | 148b335dd345347af24487d6130bc713a6387bdc (diff) | |
download | git-bug-7f87eb8602b76acbf3acc91391249d0e76424db6.tar.gz |
doc: generate concurrently
Diffstat (limited to 'doc/gen_docs.go')
-rw-r--r-- | doc/gen_docs.go | 40 |
1 files changed, 21 insertions, 19 deletions
diff --git a/doc/gen_docs.go b/doc/gen_docs.go index 83997488..8bb596fe 100644 --- a/doc/gen_docs.go +++ b/doc/gen_docs.go @@ -5,8 +5,10 @@ import ( "os" "path" "path/filepath" + "sync" "time" + "github.com/spf13/cobra" "github.com/spf13/cobra/doc" "github.com/MichaelMure/git-bug/commands" @@ -15,34 +17,34 @@ import ( func main() { fmt.Println("Generating documentation ...") - tasks := map[string]func() error{ + tasks := map[string]func(*cobra.Command) error{ "ManPage": genManPage, "Markdown": genMarkdown, } - // Due to concurrency issues in cobra, the following can't be concurrent :( - - // var wg sync.WaitGroup + 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.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) } - // wg.Wait() + wg.Wait() } -func genManPage() error { +func genManPage(root *cobra.Command) error { cwd, _ := os.Getwd() dir := path.Join(cwd, "doc", "man") + // fixed date to avoid having to commit each month date := time.Date(2019, 4, 1, 12, 0, 0, 0, time.UTC) header := &doc.GenManHeader{ @@ -62,10 +64,10 @@ func genManPage() error { } } - return doc.GenManTree(commands.NewRootCommand(), header, dir) + return doc.GenManTree(root, header, dir) } -func genMarkdown() error { +func genMarkdown(root *cobra.Command) error { cwd, _ := os.Getwd() dir := path.Join(cwd, "doc", "md") @@ -79,5 +81,5 @@ func genMarkdown() error { } } - return doc.GenMarkdownTree(commands.NewRootCommand(), dir) + return doc.GenMarkdownTree(root, dir) } |