feat(args): support a multiple modifier for arguments - #259
Open
LandonSchropp wants to merge 8 commits into
Open
feat(args): support a multiple modifier for arguments#259LandonSchropp wants to merge 8 commits into
multiple modifier for arguments#259LandonSchropp wants to merge 8 commits into
Conversation
Infer `T[]` for args declared `multiple: true`, keeping the scalar required/default logic for single-valued args. The array element type stays `T` regardless of cardinality; `required`/`multiple` only affect the array length at runtime.
Pure refactor with no behavior change. Dedupe the name-or-alias set lookup shared by getType and isStringType into isInSet, and pull the per-value coercion out of the values loop into coerceValue.
Add a `multiple` option to parseRawArgs that marks options as repeatable so node:util collects their occurrences into an array instead of keeping only the last value.
Pure refactor with no behavior change. Move the enum options check out of the parse loop into a reusable helper.
Normalize a `multiple` flag to an array of its repeated values, defaulting to an empty array, and fail a required `multiple` flag that receives none.
A `multiple` positional is variadic and consumes the remaining positional tokens, defaulting to an empty array. Only the last positional may be `multiple` — an earlier one is a definition-time error.
Render a trailing ellipsis on repeatable flags and variadic positionals so help output shows their cardinality.
Add a `multiple` row to the options table and a Multiple Values section with the cardinality matrix and examples.
📝 WalkthroughWalkthroughAdds ChangesMultiple argument support
Estimated code review effort: 3 (Moderate) | ~20 minutes Sequence Diagram(s)sequenceDiagram
participant CLI
participant parseArgs
participant parseRawArgs
participant Usage
CLI->>parseArgs: provide argument definitions and argv
parseArgs->>parseRawArgs: configure and parse multiple options
parseRawArgs-->>parseArgs: return collected arrays
parseArgs-->>CLI: return validated parsed arguments
CLI->>Usage: render command usage
Usage-->>CLI: show repeatable and variadic markers
Possibly related PRs
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
4 tasks
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.
Closes #258.
Adds an optional
multiple?: booleanmodifier to argument definitions. Combined with the existingrequired?: boolean, it covers the full cardinality matrix (both default tofalse, so the change is additive and non-breaking). It applies tostring,enum, andpositionalargs: repeated flags collect into an array and amultiplepositional is variadic. Type inference flips toT[]accordingly, and usage output marks the repeatability.See #258 for the full rationale, cardinality matrix, and examples.