WriteReport creates and writes a report using the provided data and options. It returns the created report so it can be used for further processing (e.g., VSA validation).
(data ReportData, opts ReportOutputOptions, cmd *cobra.Command)
| 158 | // WriteReport creates and writes a report using the provided data and options. |
| 159 | // It returns the created report so it can be used for further processing (e.g., VSA validation). |
| 160 | func WriteReport(data ReportData, opts ReportOutputOptions, cmd *cobra.Command) (applicationsnapshot.Report, error) { |
| 161 | report, err := applicationsnapshot.NewReport( |
| 162 | data.Snapshot, |
| 163 | data.Components, |
| 164 | data.Policy, |
| 165 | data.PolicyInputs, |
| 166 | data.ShowSuccesses, |
| 167 | data.ShowWarnings, |
| 168 | data.ShowPolicyDocsLink, |
| 169 | data.Expansion, |
| 170 | ) |
| 171 | if err != nil { |
| 172 | return applicationsnapshot.Report{}, err |
| 173 | } |
| 174 | |
| 175 | formatOpts := format.Options{ |
| 176 | ShowSuccesses: data.ShowSuccesses, |
| 177 | ShowWarnings: data.ShowWarnings, |
| 178 | ShowPolicyDocsLink: data.ShowPolicyDocsLink, |
| 179 | } |
| 180 | p := format.NewTargetParser( |
| 181 | applicationsnapshot.JSON, |
| 182 | formatOpts, |
| 183 | cmd.OutOrStdout(), |
| 184 | utils.FS(cmd.Context()), |
| 185 | ) |
| 186 | utils.SetColorEnabled(opts.NoColor, opts.ForceColor) |
| 187 | |
| 188 | if err := report.WriteAll(opts.Output, p); err != nil { |
| 189 | return applicationsnapshot.Report{}, err |
| 190 | } |
| 191 | return report, nil |
| 192 | } |
| 193 | |
| 194 | // ProcessOutputForImageValidation processes an output.Output using the same pipeline |
| 195 | // as the validate image command. This ensures consistent processing for both |