fix: ensure non-zero exit code for unknown CLI flags#213
Open
codxbrexx wants to merge 1 commit intometacall:masterfrom
Open
fix: ensure non-zero exit code for unknown CLI flags#213codxbrexx wants to merge 1 commit intometacall:masterfrom
codxbrexx wants to merge 1 commit intometacall:masterfrom
Conversation
- Add ErrorCode.InvalidArguments = 7 - printHelp() now accepts optional exitCode param (default: ErrorCode.Ok) - handleUnknownArgs() exits with InvalidArguments for unknown flags, ErrorCode.Ok only for --help / -h - Add test/unknown.spec.ts with 9 unit tests
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
Previously, when an unrecognized flag was passed to the CLI (e.g.,
metacall-deploy --invalid), the program would print a warning and the help message but exit with code0. This made it impossible for CI/CD pipelines or scripts to detect usage errors.What changed?
src/deploy.ts: IntroducedErrorCode.InvalidArguments = 7to theErrorCodeenum.src/help.ts: RefactoredprintHelp()to accept an optionalexitCodeparameter (defaulting toErrorCode.Okfor backward compatibility and explicit--helpcalls).src/cli/unknown.ts: UpdatedhandleUnknownArgs()to callprintHelp(ErrorCode.InvalidArguments)when unknown flags are detected. It still exits with0for-hor--help.src/test/unknown.spec.ts: Created a comprehensive unit test suite (9 tests) that stubsprocess.exitandconsole.logto verify that the correct exit codes are returned for various flag combinations (valid help, single unknown, multiple unknown, etc.).Resolves
Fixes #212
Testing
npm run unithas been executed../dist/index.js --invalid-flagnow correctly returns an exit code of7.