(outputFile string)
| 315 | } |
| 316 | |
| 317 | func generateJSONSchemaMain(outputFile string) { |
| 318 | // Create a Cortex config instance |
| 319 | cfg := &cortex.Config{} |
| 320 | |
| 321 | // Parse CLI flags to map them with config fields |
| 322 | flags := parseFlags(cfg) |
| 323 | |
| 324 | // Parse the config structure |
| 325 | blocks, err := parseConfig(nil, cfg, flags, map[string]struct{}{}) |
| 326 | if err != nil { |
| 327 | fmt.Fprintf(os.Stderr, "Error parsing config: %s\n", err.Error()) |
| 328 | os.Exit(1) |
| 329 | } |
| 330 | |
| 331 | // Annotate the flags prefix for each root block |
| 332 | annotateFlagPrefix(blocks) |
| 333 | |
| 334 | // Generate JSON schema |
| 335 | var output io.Writer |
| 336 | if outputFile != "" { |
| 337 | file, err := os.Create(outputFile) |
| 338 | if err != nil { |
| 339 | fmt.Fprintf(os.Stderr, "Error creating file: %s\n", err.Error()) |
| 340 | os.Exit(1) |
| 341 | } |
| 342 | defer file.Close() |
| 343 | output = file |
| 344 | } else { |
| 345 | output = os.Stdout |
| 346 | } |
| 347 | |
| 348 | writer := NewJSONSchemaWriter(output) |
| 349 | err = writer.WriteSchema(blocks) |
| 350 | if err != nil { |
| 351 | fmt.Fprintf(os.Stderr, "Error writing JSON schema: %s\n", err.Error()) |
| 352 | os.Exit(1) |
| 353 | } |
| 354 | |
| 355 | if outputFile != "" { |
| 356 | fmt.Printf("JSON schema written to %s\n", outputFile) |
| 357 | } |
| 358 | } |
| 359 | |
| 360 | func main() { |
| 361 | // Parse the generator flags. |
no test coverage detected