fix(cli): default to text format when --format is omitted#7
Open
dmchaledev wants to merge 1 commit into
Open
Conversation
The headline command `sbom-diff <old> <new>` (and the npx one-liner in the
README) crashed for every user. With no --format flag, `args.indexOf('--format')`
returned -1, so `args[-1 + 1]` read the first file path as the format value,
producing 'Unsupported format: <path>'.
Extract argument parsing into a pure, tested `parseArgs` helper that:
- defaults to 'text' when --format is absent
- handles both '--format json' and '--format=json' in any position
- reports invalid formats and missing args with a clean message (no stack trace)
Add args.test.ts covering the regression and each invocation form.
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 tool's headline command — the very first example in the README and the
npxone-liner — crashes for every user:Root cause
In
src/cli.tsthe--formatvalue was resolved with:When
--formatis absent,args.indexOf('--format')returns-1, soargs[-1 + 1]→args[0]— the first file path — gets used as the format.renderReportthen throws on the unknown format.So the documented default usage (text output, no flag) was completely broken; only the explicit
--format=json/--format markdownforms worked.Fix
parseArgshelper (src/args.ts).textwhen--formatis omitted.--format jsonand--format=json, and consume the space-separated value so it isn't mistaken for a positional file argument (this also makes flag-before-files ordering work).ArgError).Tests
Added
src/__tests__/args.test.tscovering the regression and every invocation form (default,--format=value,--format value, flag-first, missing args, invalid format).Verification
npm run lint,npm run typecheck,npm test(26 passed), andnpm run buildall pass.https://claude.ai/code/session_01LuhAMY6e7HPmHMGWGeCiVh
Generated by Claude Code