MCPcopy Create free account
hub / github.com/conforma/cli / writeDataToOutput

Function writeDataToOutput

cmd/validate/vsa.go:1454–1477  ·  view source on GitHub ↗

writeDataToOutput writes data to stdout or a file, adding a newline if needed This is shared between ComponentResultsDisplay.WriteAll and writeVSAReport

(data []byte, formatName, file string, fs afero.Fs, cmd *cobra.Command)

Source from the content-addressed store, hash-verified

1452// writeDataToOutput writes data to stdout or a file, adding a newline if needed
1453// This is shared between ComponentResultsDisplay.WriteAll and writeVSAReport
1454func writeDataToOutput(data []byte, formatName, file string, fs afero.Fs, cmd *cobra.Command) error {
1455 var writer io.Writer = cmd.OutOrStdout()
1456 if file != "" {
1457 f, err := fs.Create(file)
1458 if err != nil {
1459 return fmt.Errorf("failed to create output file %s: %w", file, err)
1460 }
1461 defer f.Close()
1462 writer = f
1463 }
1464
1465 if _, err := writer.Write(data); err != nil {
1466 return fmt.Errorf("failed to write %s output: %w", formatName, err)
1467 }
1468
1469 // Add newline if not present
1470 if !strings.HasSuffix(string(data), "\n") {
1471 if _, err := writer.Write([]byte("\n")); err != nil {
1472 return fmt.Errorf("failed to write newline: %w", err)
1473 }
1474 }
1475
1476 return nil
1477}
1478
1479// stringWriter is a helper to capture text output from WriteAll
1480type stringWriter struct {

Callers 3

WriteAllMethod · 0.85
writeVSAReportFunction · 0.85
writeStatusOutputFunction · 0.85

Calls 3

ErrorfMethod · 0.65
CloseMethod · 0.65
WriteMethod · 0.45

Tested by

no test coverage detected