Skip to content

feat: add [String] and [Number] option types - #396

Merged
dangreen merged 1 commit into
masterfrom
feat/list-option-readers
Sep 1, 2026
Merged

feat: add [String] and [Number] option types#396
dangreen merged 1 commit into
masterfrom
feat/list-option-readers

Conversation

@dangreen

@dangreen dangreen commented Sep 1, 2026

Copy link
Copy Markdown
Member

Adds a list form to option: [String] and [Number] take the next argument as a whole and collect repeated options, instead of splitting it.

readOptions(
  option(alias('match', 'm'), [String]),   // ['**/*.{jpg,png}', '(min-width: 1000px)']
  option(alias('width', 'w'), Array)       // unchanged: '1920,1280' -> ['1920', '1280']
)

Why

Array splits every value by commas, so a value that carries commas of its own does not survive:

cli -m '**/*.{jpg,png}'                          # -> ['**/*.{jpg', 'png}']
cli -m '(min-width: 100px), (max-width: 200px)'  # -> two queries instead of one list

Both are ordinary inputs — a brace glob and a media query list — and there was no way to opt out of the splitting: String keeps the value whole but silently drops all but the last repeated option.

A consumer can work around it by re-joining and re-splitting brace-aware, but that only covers braces, and the alias plus camelCase/kebab-case matching lives in the non-exported matchArgName, so a custom reader means forking that part.

What changed

  • ListConstructor and OptionConstructor types, plus the two branches in OptionValueType[String] infers string[], [Number] infers number[];
  • an Array.isArray(type) branch in option;
  • PrimitiveConstructor is untouched, so nothing that used it before changes.

The pinned bundle size moved by 5 B (850 B → 855 B), so .size-limit.json is re-pinned to 900 B on the 0.05 kB step.

…options

The `Array` type splits every value by commas, which mangles values that
carry commas of their own - a brace glob or a media query list. The list
types take the argument as it is and collect the repeated options instead.
@codecov

codecov Bot commented Sep 1, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.47%. Comparing base (0594f8a) to head (ff5f11f).

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #396      +/-   ##
==========================================
+ Coverage   98.34%   98.47%   +0.12%     
==========================================
  Files           5        5              
  Lines         121      131      +10     
  Branches       31       35       +4     
==========================================
+ Hits          119      129      +10     
  Misses          2        2              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@dangreen
dangreen merged commit 23d6fb9 into master Sep 1, 2026
8 checks passed
@dangreen
dangreen deleted the feat/list-option-readers branch September 1, 2026 12:37
@github-actions github-actions Bot mentioned this pull request Sep 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant