cmdref.go
// SPDX-License-Identifier: Apache-2.0
// Copyright 2018-2020 Authors of Cilium
package main
import (
"fmt"
"strings"
"github.com/spf13/cobra"
"github.com/spf13/cobra/doc"
)
func linkHandler(s string) string {
// The generated files have a 'See also' section but the URL's are
// hardcoded to use Markdown but we only want / have them in HTML
// later.
return strings.Replace(s, ".md", ".html", 1)
}
func filePrepend(s string) string {
// Prepend a HTML comment that this file is autogenerated. So that
// users are warned before fixing issues in the Markdown files. Should
// never show up on the web.
return fmt.Sprintf("%s\n\n", "<!-- This file was autogenerated via cilium-operator --cmdref, do not edit manually-->")
}
func genMarkdown(cmd *cobra.Command, cmdRefDir string) {
// Remove the line 'Auto generated by spf13/cobra on ...'
cmd.DisableAutoGenTag = true
if err := doc.GenMarkdownTreeCustom(cmd, cmdRefDir, filePrepend, linkHandler); err != nil {
log.Fatal(err)
}
}