()
| 358 | } |
| 359 | |
| 360 | func 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) |
nothing calls this directly
no test coverage detected