Skip to content

Commit

Permalink
promtool docs: write flags between backtits in help
Browse files Browse the repository at this point in the history
Signed-off-by: Julien Pivotto <roidelapluie@o11y.eu>
  • Loading branch information
roidelapluie committed Jul 13, 2023
1 parent b3b669f commit d908b5a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion docs/command-line/promtool.md
Expand Up @@ -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.



Expand Down
10 changes: 10 additions & 0 deletions util/documentcli/documentcli.go
Expand Up @@ -23,6 +23,7 @@ import (
"bytes"
"fmt"
"io"
"regexp"

Check failure on line 26 in util/documentcli/documentcli.go

View workflow job for this annotation

GitHub Actions / golangci-lint

import 'regexp' is not allowed from list 'main': Use github.com/grafana/regexp instead of regexp (depguard)

Check failure on line 26 in util/documentcli/documentcli.go

View workflow job for this annotation

GitHub Actions / codeql / Analyze (go)

import 'regexp' is not allowed from list 'main': Use github.com/grafana/regexp instead of regexp (depguard)
"strings"

"github.com/alecthomas/kingpin/v2"
Expand Down Expand Up @@ -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
}
Expand All @@ -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)
}

0 comments on commit d908b5a

Please sign in to comment.