From fd5b01afdcb1fefad227b9f7667125e02a1395f1 Mon Sep 17 00:00:00 2001 From: Julien Pivotto Date: Thu, 13 Jul 2023 22:26:49 +0200 Subject: [PATCH] promtool docs: write flags between backtits in help Signed-off-by: Julien Pivotto --- docs/command-line/promtool.md | 2 +- util/documentcli/documentcli.go | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/docs/command-line/promtool.md b/docs/command-line/promtool.md index 587286e10..546b200e2 100644 --- a/docs/command-line/promtool.md +++ b/docs/command-line/promtool.md @@ -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. diff --git a/util/documentcli/documentcli.go b/util/documentcli/documentcli.go index c199d8d9b..720a7c9c7 100644 --- a/util/documentcli/documentcli.go +++ b/util/documentcli/documentcli.go @@ -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) +}