promtool docs: write flags between backtits in help

Signed-off-by: Julien Pivotto <roidelapluie@o11y.eu>
This commit is contained in:
Julien Pivotto 2023-07-13 22:26:49 +02:00
parent b3b669fd9a
commit fd5b01afdc
2 changed files with 11 additions and 1 deletions

View File

@ -615,7 +615,7 @@ Create blocks of data for new recording rules.
### `promtool promql`
PromQL formatting and editing. Requires the --experimental flag.
PromQL formatting and editing. Requires the `--experimental` flag.

View File

@ -26,6 +26,7 @@ import (
"strings"
"github.com/alecthomas/kingpin/v2"
"github.com/grafana/regexp"
)
// GenerateMarkdown generates the markdown documentation for an application from
@ -230,6 +231,7 @@ func writeSubcommands(writer io.Writer, level int, modelName string, commands []
if cmd.HelpLong != "" {
help = cmd.HelpLong
}
help = formatHyphenatedWords(help)
if _, err := writer.Write([]byte(fmt.Sprintf("\n\n%s `%s %s`\n\n%s\n\n", strings.Repeat("#", level+1), modelName, cmd.FullCommand, help))); err != nil {
return err
}
@ -250,3 +252,11 @@ func writeSubcommands(writer io.Writer, level int, modelName string, commands []
}
return nil
}
func formatHyphenatedWords(input string) string {
hyphenRegex := regexp.MustCompile(`\B--\w+\b`)
replacer := func(s string) string {
return fmt.Sprintf("`%s`", s)
}
return hyphenRegex.ReplaceAllStringFunc(input, replacer)
}