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

Function generateJSONSchemaMain

tools/doc-generator/main.go:317–358  ·  view source on GitHub ↗
(outputFile string)

Source from the content-addressed store, hash-verified

315}
316
317func 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
360func main() {
361 // Parse the generator flags.

Callers 1

mainFunction · 0.85

Calls 7

WriteSchemaMethod · 0.95
parseFlagsFunction · 0.85
parseConfigFunction · 0.85
annotateFlagPrefixFunction · 0.85
NewJSONSchemaWriterFunction · 0.85
CloseMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected