writeStatusOutput writes only the status format output based on overall result
(allData AllSectionsData, outputFormats []string, cmd *cobra.Command)
| 1578 | |
| 1579 | // writeStatusOutput writes only the status format output based on overall result |
| 1580 | func writeStatusOutput(allData AllSectionsData, outputFormats []string, cmd *cobra.Command) error { |
| 1581 | resultStr := statusFailure |
| 1582 | if allData.OverallPassed { |
| 1583 | resultStr = statusSuccess |
| 1584 | } |
| 1585 | |
| 1586 | statusReport := map[string]string{"result": resultStr} |
| 1587 | data, err := json.Marshal(statusReport) |
| 1588 | if err != nil { |
| 1589 | return fmt.Errorf("failed to marshal status report: %w", err) |
| 1590 | } |
| 1591 | |
| 1592 | // Parse output spec to get file path if specified |
| 1593 | for _, outputSpec := range outputFormats { |
| 1594 | _, file := parseOutputSpec(outputSpec) |
| 1595 | fs := utils.FS(cmd.Context()) |
| 1596 | if err := writeDataToOutput(data, outputFormatStatus, file, fs, cmd); err != nil { |
| 1597 | return err |
| 1598 | } |
| 1599 | } |
| 1600 | |
| 1601 | return nil |
| 1602 | } |
| 1603 | |
| 1604 | // isStatusOnlyFormat checks if the output formats contain only "status" format |
| 1605 | func isStatusOnlyFormat(outputFormats []string) bool { |
no test coverage detected