Skip to content

[K9VULN-9309] Add --pretty option support#77

Merged
piloulacdog merged 2 commits intomainfrom
pierrelouis.lacorte/K9VULN-9309-add-prettyfier
Oct 31, 2025
Merged

[K9VULN-9309] Add --pretty option support#77
piloulacdog merged 2 commits intomainfrom
pierrelouis.lacorte/K9VULN-9309-add-prettyfier

Conversation

@piloulacdog
Copy link
Copy Markdown
Contributor

@piloulacdog piloulacdog commented Oct 30, 2025

What problem are you trying to solve?

  • Users need a way to format SBOM output in a more readable format for human consumption
  • K9VULN-9309

What is your solution?

Added a --pretty flag to the SBOM generator that enables pretty-printing of JSON output. The implementation:

  • Added the --pretty flag to the CLI interface
  • Modified all output formatters (JSON, CycloneDX) to support pretty formatting
  • Updated the reporter interfaces to pass through the pretty-printing option
  • Ensured backward compatibility with existing output formats

Alternatives considered

  • Could have made pretty-printing the default behavior, but this would change customer existing usage
  • Could have added format-specific flags, but a single --pretty flag is simpler and more intuitive

What the reviewer should know

  • All existing output formats maintain their structure, only formatting changes when --pretty is enabled
  • Tests have been updated to cover both pretty and compact output scenarios
  • The change affects multiple output formats consistently

---

[TestRun/not_lockfile_and_not_formatter - 1]
{"$schema":"http://cyclonedx.org/schema/bom-1.5.schema.json","bomFormat":"CycloneDX","specVersion":"1.5","version":1,"metadata":{"tools":{"components":[{"type":"application","group":"datadog","name":"datadog-sbom-generator","version":"set at build time, see .goreleaser.yml ldflags section"}]}}}
Copy link
Copy Markdown
Contributor Author

@piloulacdog piloulacdog Oct 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we make sure we are still able to output minified sbom by default

},
{
name: "not lockfile",
args: []string{"", "--pretty", "./fixtures/no-lockfile.txt"},
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

before we were assuming that: if you are in a Test -> always prettify, but this means we cannot test that we are able to minifiy.. so had to add --pretty everywhere we expected it

@github-actions
Copy link
Copy Markdown

Go test coverage report

Total test coverage: 90.9% (3932/4325)

No coverage changes in any files compared to the base.

encoder := json.NewEncoder(outputWriter)
encoder.SetIndent("", " ")
if pretty {
encoder.SetIndent("", " ")
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we are somewhere screwed here. Because:

  1. default behavior of JSON formatter was pretty = true
  2. default behavior of cycloneDX formatter was pretty = false

Because of it, we cannot have a flag --pretty as an input which would rule both without causing change to existing default behavior. Because the format: cycloneDX is the default behavior, I've decided to make its behavior be the one which doesn't change (default pretty = false).

@piloulacdog piloulacdog marked this pull request as ready for review October 30, 2025 16:23
@piloulacdog piloulacdog requested a review from a team as a code owner October 30, 2025 16:23
@piloulacdog piloulacdog merged commit 90a50ef into main Oct 31, 2025
11 checks passed
@piloulacdog piloulacdog deleted the pierrelouis.lacorte/K9VULN-9309-add-prettyfier branch October 31, 2025 09:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants