Prepend Docusorus front matter to auto-gen CLI commands (#713)
* Pre-pend dark to auto-gen CLI commands * After `gofmt -s` * Update src/cmd/mdgen/mdgen.go Co-authored-by: Keepers <ryanfkeepers@gmail.com> * More gofmt Co-authored-by: Keepers <ryanfkeepers@gmail.com>
This commit is contained in:
parent
8ead744e9f
commit
dcbfed15df
@ -3,6 +3,7 @@ package main
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
@ -26,6 +27,12 @@ var cmd = &cobra.Command{
|
|||||||
Run: genDocs,
|
Run: genDocs,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const fmTemplate = `---
|
||||||
|
title: "%s"
|
||||||
|
hide_title: true
|
||||||
|
---
|
||||||
|
`
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
cmd.
|
cmd.
|
||||||
PersistentFlags().
|
PersistentFlags().
|
||||||
@ -41,11 +48,22 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func genDocs(cmd *cobra.Command, args []string) {
|
func genDocs(cmd *cobra.Command, args []string) {
|
||||||
|
identity := func(s string) string { return s }
|
||||||
|
filePrepender := func(filename string) string {
|
||||||
|
name := filepath.Base(filename)
|
||||||
|
base := strings.TrimSuffix(name, filepath.Ext(name))
|
||||||
|
|
||||||
|
return fmt.Sprintf(fmTemplate, strings.Replace(base, "_", " ", -1))
|
||||||
|
}
|
||||||
|
|
||||||
if err := makeDir(cliMarkdownDir); err != nil {
|
if err := makeDir(cliMarkdownDir); err != nil {
|
||||||
fatal(errors.Wrap(err, "preparing directory for markdown generation"))
|
fatal(errors.Wrap(err, "preparing directory for markdown generation"))
|
||||||
}
|
}
|
||||||
|
|
||||||
err := doc.GenMarkdownTree(cli.CorsoCommand(), cliMarkdownDir)
|
corsoCmd := cli.CorsoCommand()
|
||||||
|
corsoCmd.DisableAutoGenTag = true
|
||||||
|
|
||||||
|
err := doc.GenMarkdownTreeCustom(corsoCmd, cliMarkdownDir, filePrepender, identity)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fatal(errors.Wrap(err, "generating the Corso CLI markdown"))
|
fatal(errors.Wrap(err, "generating the Corso CLI markdown"))
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user