1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374 |
- package main
- import (
- "io/ioutil"
- "path/filepath"
- "strings"
- "github.com/spf13/cobra"
- )
- func MarkdownPostProcessing(cmd *cobra.Command, dir string, processor func(string) string) error {
- for _, c := range cmd.Commands() {
- if !c.IsAvailableCommand() || c.IsAdditionalHelpTopicCommand() {
- continue
- }
- if err := MarkdownPostProcessing(c, dir, processor); err != nil {
- return err
- }
- }
- basename := strings.Replace(cmd.CommandPath(), " ", "_", -1) + ".md"
- filename := filepath.Join(dir, basename)
- markdownBytes, err := ioutil.ReadFile(filename)
- if err != nil {
- return err
- }
- processedMarkDown := processor(string(markdownBytes))
- return ioutil.WriteFile(filename, []byte(processedMarkDown), 0644)
- }
- func cleanupForInclude(md string) string {
- lines := strings.Split(md, "\n")
- cleanMd := ""
- for i, line := range lines {
- if i == 0 {
- continue
- }
- if line == "### SEE ALSO" {
- break
- }
- cleanMd += line
- if i < len(lines)-1 {
- cleanMd += "\n"
- }
- }
- return cleanMd
- }
|