(block *configBlock)
| 125 | } |
| 126 | |
| 127 | func (w *markdownWriter) writeConfigBlock(block *configBlock) { |
| 128 | // Title |
| 129 | if block.name != "" { |
| 130 | w.out.WriteString("### `" + block.name + "`\n") |
| 131 | w.out.WriteString("\n") |
| 132 | } |
| 133 | |
| 134 | // Description |
| 135 | if block.desc != "" { |
| 136 | desc := block.desc |
| 137 | |
| 138 | // Wrap the config block name with backticks |
| 139 | if block.name != "" { |
| 140 | desc = regexp.MustCompile(regexp.QuoteMeta(block.name)).ReplaceAllStringFunc(desc, func(input string) string { |
| 141 | return "`" + input + "`" |
| 142 | }) |
| 143 | } |
| 144 | |
| 145 | // List of all prefixes used to reference this config block. |
| 146 | if len(block.flagsPrefixes) > 1 { |
| 147 | sortedPrefixes := sort.StringSlice(block.flagsPrefixes) |
| 148 | sortedPrefixes.Sort() |
| 149 | |
| 150 | desc += " The supported CLI flags `<prefix>` used to reference this config block are:\n\n" |
| 151 | |
| 152 | for _, prefix := range sortedPrefixes { |
| 153 | if prefix == "" { |
| 154 | desc += "- _no prefix_\n" |
| 155 | } else { |
| 156 | desc += fmt.Sprintf("- `%s`\n", prefix) |
| 157 | } |
| 158 | } |
| 159 | |
| 160 | // Unfortunately the markdown compiler used by the website generator has a bug |
| 161 | // when there's a list followed by a code block (no matter know many newlines |
| 162 | // in between). To workaround it we add a non-breaking space. |
| 163 | desc += "\n " |
| 164 | } |
| 165 | |
| 166 | w.out.WriteString(desc + "\n") |
| 167 | w.out.WriteString("\n") |
| 168 | } |
| 169 | |
| 170 | // Config specs |
| 171 | spec := &specWriter{} |
| 172 | spec.writeConfigBlock(block, 0) |
| 173 | |
| 174 | w.out.WriteString("```yaml\n") |
| 175 | w.out.WriteString(spec.string() + "\n") |
| 176 | w.out.WriteString("```\n") |
| 177 | w.out.WriteString("\n") |
| 178 | } |
| 179 | |
| 180 | func (w *markdownWriter) string() string { |
| 181 | return strings.TrimSpace(w.out.String()) |
no test coverage detected