fix(cli): default to text format when --format is omitted#6
Open
dmchaledev wants to merge 1 commit into
Open
Conversation
The default documented invocation `sbom-diff old.json new.json` crashed
with "Unsupported format". When --format was absent, args.indexOf('--format')
returned -1, so args[0] (the old file path) was used as the format value and
renderReport() threw.
- Extract a tested resolveFormat() helper supporting both `--format x` and
`--format=x`, defaulting to 'text' when absent/empty
- Validate the value and emit a clean one-line error (no stack trace) for
unsupported formats
- Guard main() so it only runs when invoked directly, enabling unit tests
- Add cli.test.ts regression coverage
- Fix the README programmatic example to match the real API (parse + diff
on SBOM objects, not file paths)
https://claude.ai/code/session_014i1tcsdNL9uaFYgd34bTV6
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The primary documented CLI invocation crashes:
This is the very first example in the README's Quick Start, so every new user following the docs hits it.
Root cause
In
src/cli.ts, format parsing fell through to the positional form even when--formatwas absent:When
--formatis not passed,args.indexOf('--format')returns-1, soargs[-1 + 1]→args[0]→ the old file path gets used as the format.renderReport()then throws on the unknown format.Fix
resolveFormat()helper that supports both--format jsonand--format=json, and defaults totextwhen the flag is absent or empty.Unsupported format: xml. Valid formats: text, json, markdown.main()so it only runs when the module is invoked directly, enabling unit testing of the parser.src/__tests__/cli.test.tsregression coverage.await diff('old.cdx.json', 'new.cdx.json')(file paths, async), butdiff()takes two parsedSBOMobjects and is synchronous. Updated toparse()+diff()matching the real API, and corrected the return-type comments (VersionChange[],CVEEntry[]).Verification
npm run lint,npm run typecheck, andnpm testall pass (25 tests, including 5 new CLI tests).https://claude.ai/code/session_014i1tcsdNL9uaFYgd34bTV6
Generated by Claude Code