feat(helm): Allow generating markdown docs headers

For backwards-compatibility, the generation of markdown headers is
only enabled through the --generate-headers flag.

Signed-off-by: Marc Khouzam <marc.khouzam@montreal.ca>
pull/9029/head
Marc Khouzam 4 years ago committed by Marc Khouzam
parent b266c2ef0f
commit d9c5754dfc

@ -16,8 +16,11 @@ limitations under the License.
package main
import (
"fmt"
"io"
"path"
"path/filepath"
"strings"
"github.com/pkg/errors"
"github.com/spf13/cobra"
@ -41,6 +44,7 @@ type docsOptions struct {
dest string
docTypeString string
topCmd *cobra.Command
generateHeaders bool
}
func newDocsCmd(out io.Writer) *cobra.Command {
@ -62,6 +66,7 @@ func newDocsCmd(out io.Writer) *cobra.Command {
f := cmd.Flags()
f.StringVar(&o.dest, "dir", "./", "directory to which documentation is written")
f.StringVar(&o.docTypeString, "type", "markdown", "the type of documentation to generate (markdown, man, bash)")
f.BoolVar(&o.generateHeaders, "generate-headers", false, "generate standard headers for markdown files")
return cmd
}
@ -69,6 +74,18 @@ func newDocsCmd(out io.Writer) *cobra.Command {
func (o *docsOptions) run(out io.Writer) error {
switch o.docTypeString {
case "markdown", "mdown", "md":
if o.generateHeaders {
standardLinks := func(s string) string { return s }
hdrFunc := func(filename string) string {
base := filepath.Base(filename)
name := strings.TrimSuffix(base, path.Ext(base))
title := strings.Title(strings.Replace(name, "_", " ", -1))
return fmt.Sprintf("---\ntitle: \"%s\"\n---\n\n", title)
}
return doc.GenMarkdownTreeCustom(o.topCmd, o.dest, hdrFunc, standardLinks)
}
return doc.GenMarkdownTree(o.topCmd, o.dest)
case "man":
manHdr := &doc.GenManHeader{Title: "HELM", Section: "1"}

Loading…
Cancel
Save