Home

tmpl @0b0de4be3589a92ce64970b0524fc729f75b626a - refs - log -
-
https://git.jolheiser.com/tmpl.git
Template automation
tmpl / docs.go
- raw
 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
// +build docs

package main

import (
	"os"
	"regexp"
	"strings"

	"go.jolheiser.com/tmpl/cmd"
)

func main() {
	app := cmd.NewApp()

	fi, err := os.Create("CLI.md")
	if err != nil {
		panic(err)
	}
	defer fi.Close()

	md, err := app.ToMarkdown()
	if err != nil {
		panic(err)
	}

	// CLI ToMarkdown issue related to man-pages
	md = md[strings.Index(md, "#"):]

	// CLI is using real default instead of DefaultText
	md = regexp.MustCompile(`[\/\w]+\.tmpl`).ReplaceAllString(md, "~/.tmpl")

	if _, err := fi.WriteString(md); err != nil {
		panic(err)
	}
}