Skip to content

Commit d0dc9d9

Browse files
committed
Add demo option for both sample SBOMs
1 parent 2d5b920 commit d0dc9d9

2 files changed

Lines changed: 45 additions & 15 deletions

File tree

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ Demo options:
5757
svs demo --out reports --no-open
5858
svs demo --out reports --min-severity high
5959
svs demo --sbom path/to/your-sbom.json --out reports --summary-out svs-summary.md
60+
svs demo --both-samples --out reports
6061
```
6162

6263
## Quick SBOM generation
@@ -87,7 +88,7 @@ npm sbom --sbom-format=cyclonedx --sbom-type=application > sbom.cdx.json
8788
- Use `svs summary --report <report.json>` or `svs summary --latest --dir reports` to generate the PR summary locally.
8889
- Use `svs open-report --dir reports` (or `--path report.html`) to open the latest HTML report.
8990
- Use `svs demo --out reports` to run a full local demo (scan + summary + open report).
90-
- Demo flags: `--no-open` to skip opening the browser, `--min-severity` to filter results, `--summary-out` to control the summary filename.
91+
- Demo flags: `--no-open` to skip opening the browser, `--min-severity` to filter results, `--summary-out` to control the summary filename, `--both-samples` to scan CycloneDX + SPDX samples.
9192

9293
## Community & Governance
9394
- Code of Conduct: `CODE_OF_CONDUCT.md`

src/svs/cli.py

Lines changed: 43 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,11 @@ def demo(
264264
readable=True,
265265
help="SBOM to scan (default: examples/sample-sbom.json). CycloneDX or SPDX JSON.",
266266
),
267+
both_samples: bool = typer.Option(
268+
False,
269+
"--both-samples",
270+
help="Scan both bundled samples (CycloneDX + SPDX). Overrides --sbom.",
271+
),
267272
out: Path = typer.Option(
268273
Path("reports"),
269274
"--out",
@@ -290,22 +295,46 @@ def demo(
290295
),
291296
) -> None:
292297
"""Run a local demo: scan, write a summary, and open the HTML report."""
293-
scan(
294-
sbom=sbom,
295-
out=out,
296-
json_output=True,
297-
html_output=True,
298-
sarif_output=True,
299-
min_severity=min_severity,
300-
timeout=30,
301-
retries=3,
298+
if both_samples and sbom != Path("examples/sample-sbom.json"):
299+
raise typer.BadParameter("Use --both-samples without --sbom (or leave --sbom as default).")
300+
301+
sboms = (
302+
[Path("examples/sample-sbom.json"), Path("examples/sample-spdx.json")]
303+
if both_samples
304+
else [sbom]
302305
)
303306

304-
latest_report = _latest_json_report(out)
305-
report_data = json.loads(latest_report.read_text(encoding="utf-8"))
306-
markdown = build_pr_summary(report_data)
307-
summary_out.write_text(markdown, encoding="utf-8")
308-
console.print(f"Summary written: {summary_out}")
307+
generated_reports: list[Path] = []
308+
for sbom_path in sboms:
309+
scan(
310+
sbom=sbom_path,
311+
out=out,
312+
json_output=True,
313+
html_output=True,
314+
sarif_output=True,
315+
min_severity=min_severity,
316+
timeout=30,
317+
retries=3,
318+
)
319+
generated_reports.append(_latest_json_report(out))
320+
321+
if len(generated_reports) == 1:
322+
report_data = json.loads(generated_reports[0].read_text(encoding="utf-8"))
323+
markdown = build_pr_summary(report_data)
324+
summary_out.write_text(markdown, encoding="utf-8")
325+
console.print(f"Summary written: {summary_out}")
326+
else:
327+
summary_dir = summary_out.parent
328+
base = summary_out.stem or "svs-summary"
329+
suffix = summary_out.suffix or ".md"
330+
for report_path in generated_reports:
331+
report_data = json.loads(report_path.read_text(encoding="utf-8"))
332+
sbom_path = report_data.get("metadata", {}).get("sbom", {}).get("path") or report_path.stem
333+
sbom_name = Path(str(sbom_path)).stem
334+
target = summary_dir / f"{base}-{sbom_name}{suffix}"
335+
markdown = build_pr_summary(report_data)
336+
target.write_text(markdown, encoding="utf-8")
337+
console.print(f"Summary written: {target}")
309338

310339
if open_browser:
311340
open_report(path=None, reports_dir=out)

0 commit comments

Comments
 (0)