MCPcopy Index your code
hub / github.com/cortexproject/cortex / annotateFlagPrefix

Function annotateFlagPrefix

tools/doc-generator/main.go:227–276  ·  view source on GitHub ↗
(blocks []*configBlock)

Source from the content-addressed store, hash-verified

225}
226
227func annotateFlagPrefix(blocks []*configBlock) {
228 // Find duplicated blocks
229 groups := map[string][]*configBlock{}
230 for _, block := range blocks {
231 groups[block.name] = append(groups[block.name], block)
232 }
233
234 // For each duplicated block, we need to fix the CLI flags, because
235 // in the documentation each block will be displayed only once but
236 // since they're duplicated they will have a different CLI flag
237 // prefix, which we want to correctly document.
238 for _, group := range groups {
239 if len(group) == 1 {
240 continue
241 }
242
243 // We need to find the CLI flags prefix of each config block. To do it,
244 // we pick the first entry from each config block and then find the
245 // different prefix across all of them.
246 flags := []string{}
247 for _, block := range group {
248 for _, entry := range block.entries {
249 if entry.kind == "field" {
250 flags = append(flags, entry.fieldFlag)
251 break
252 }
253 }
254 }
255
256 allPrefixes := []string{}
257 for i, prefix := range findFlagsPrefix(flags) {
258 group[i].flagsPrefix = prefix
259 allPrefixes = append(allPrefixes, prefix)
260 }
261
262 // Store all found prefixes into each block so that when we generate the
263 // markdown we also know which are all the prefixes for each root block.
264 for _, block := range group {
265 block.flagsPrefixes = allPrefixes
266 }
267 }
268
269 // Finally, we can remove the CLI flags prefix from the blocks
270 // which have one annotated.
271 for _, block := range blocks {
272 if block.flagsPrefix != "" {
273 removeFlagPrefix(block, block.flagsPrefix)
274 }
275 }
276}
277
278func generateBlocksMarkdown(blocks []*configBlock) string {
279 md := &markdownWriter{}

Callers 2

generateJSONSchemaMainFunction · 0.85
mainFunction · 0.85

Calls 2

findFlagsPrefixFunction · 0.85
removeFlagPrefixFunction · 0.85

Tested by

no test coverage detected