MCPcopy Create free account
hub / github.com/cortexproject/cortex / main

Function main

tools/doc-generator/main.go:360–428  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

358}
359
360func main() {
361 // Parse the generator flags.
362 jsonSchema := flag.Bool("json-schema", false, "Generate JSON schema instead of markdown documentation")
363 outputFile := flag.String("output", "", "Output file for schema (default: stdout)")
364 flag.Parse()
365
366 // If JSON schema generation is requested
367 if *jsonSchema {
368 generateJSONSchemaMain(*outputFile)
369 return
370 }
371
372 if flag.NArg() != 1 {
373 fmt.Fprintf(os.Stderr, "Usage: doc-generator [-json-schema] [-output file] template-file")
374 os.Exit(1)
375 }
376
377 templatePath := flag.Arg(0)
378
379 // In order to match YAML config fields with CLI flags, we do map
380 // the memory address of the CLI flag variables and match them with
381 // the config struct fields address.
382 cfg := &cortex.Config{}
383 flags := parseFlags(cfg)
384
385 // Parse the config, mapping each config field with the related CLI flag.
386 blocks, err := parseConfig(nil, cfg, flags, map[string]struct{}{})
387 if err != nil {
388 fmt.Fprintf(os.Stderr, "An error occurred while generating the doc: %s\n", err.Error())
389 os.Exit(1)
390 }
391
392 // Annotate the flags prefix for each root block, and remove the
393 // prefix wherever encountered in the config blocks.
394 annotateFlagPrefix(blocks)
395
396 // Generate documentation markdown.
397 data := struct {
398 ConfigFile string
399 BlocksStorageConfigBlock string
400 StoreGatewayConfigBlock string
401 CompactorConfigBlock string
402 QuerierConfigBlock string
403 S3SSEConfigBlock string
404 GeneratedFileWarning string
405 }{
406 ConfigFile: generateBlocksMarkdown(blocks),
407 BlocksStorageConfigBlock: generateBlockMarkdown(blocks, "blocks_storage_config", "blocks_storage"),
408 StoreGatewayConfigBlock: generateBlockMarkdown(blocks, "store_gateway_config", "store_gateway"),
409 CompactorConfigBlock: generateBlockMarkdown(blocks, "compactor_config", "compactor"),
410 QuerierConfigBlock: generateBlockMarkdown(blocks, "querier_config", "querier"),
411 S3SSEConfigBlock: generateBlockMarkdown(blocks, "s3_sse_config", "sse"),
412 GeneratedFileWarning: "<!-- DO NOT EDIT THIS FILE - This file has been automatically generated from its .template -->",
413 }
414
415 // Load the template file.
416 tpl := template.New(filepath.Base(templatePath))
417 tpl, err = tpl.ParseFiles(templatePath)

Callers

nothing calls this directly

Calls 9

generateJSONSchemaMainFunction · 0.85
parseFlagsFunction · 0.85
parseConfigFunction · 0.85
annotateFlagPrefixFunction · 0.85
generateBlocksMarkdownFunction · 0.85
generateBlockMarkdownFunction · 0.85
ParseMethod · 0.80
StringMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected