feat(cli): add --help and --version flags#45
Open
dmchaledev wants to merge 1 commit into
Open
Conversation
The published CLI had no way to print usage or the installed version: `sbom-diff --help` threw `Unknown option: --help` and exited non-zero, which is a poor first-run experience for an npm-distributed binary. - Add `-h`/`--help` (prints usage, arguments, options, examples; exits 0) - Add `-v`/`--version` (prints the version read from the shipped package.json, resolved relative to the module so it works via npx) - Both flags short-circuit parsing so they succeed even alongside otherwise-invalid arguments, and never throw - Document the flags in the README and add parseArgs test coverage Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Wsn1rRnwNaxcCqP1vRuzPZ
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.
Summary
The published
sbom-diffCLI has no way to print usage or its version. Because unknown flags throw, the two commands a user reflexively runs first both fail:For an npm-distributed binary, a broken
--help/--versionis a poor first-run experience and a discoverability gap. This PR adds both, self-contained tocli.ts.Changes
-h/--help— prints usage, arguments, options, and examples, then exits0.-v/--version— prints the version read from the shippedpackage.json, resolved relative to the module (new URL('../package.json', import.meta.url)) so it works both fromdist/and vianpx. Falls back gracefully if the file can't be read.sbom-diff --help --format=yaml) and never throw.parseArgstest coverage for--help/-h,--version/-v, the short-circuit behavior, and that normal invocations set neither flag.Behavior after this change
Scope / compatibility
src/cli.ts,src/__tests__/cli.test.ts, andREADME.md.ParsedArgsgainshelp/versionbooleans; existing fields and default behavior are unchanged.npm run lint,npm run typecheck,npm test(33 passing), andnpm run buildall green; verified the built CLI end-to-end.🤖 Generated with Claude Code
https://claude.ai/code/session_01Wsn1rRnwNaxcCqP1vRuzPZ
Generated by Claude Code