Skip to content

feat: type: 'number' flags, long-form aliases, and unparseFlags()#38

Draft
voxpelli wants to merge 4 commits into
mainfrom
feat/number-aliases-unparse
Draft

feat: type: 'number' flags, long-form aliases, and unparseFlags()#38
voxpelli wants to merge 4 commits into
mainfrom
feat/number-aliases-unparse

Conversation

@voxpelli
Copy link
Copy Markdown
Owner

Summary

Three related features for Mocha and similar CLI tools that need richer flag declarations than util.parseArgs() exposes:

  • type: 'number' flag support — declare numeric flags directly; peowly remaps them to type: 'string' before parseArgs and coerces back afterwards, with NaN validation and full default/multiple support
  • aliases: string[] — long-form argv aliases (e.g. --colors → --color) rewritten before parsing; supports plain, =value, and multiple-alias forms; opt-in help annotation via showAliasInHelp: true; collision detection throws on duplicate or conflicting names
  • unparseFlags(flags, flagDefs) → string[] — serialises a parsed flags object back to an argv array for child_process.spawn(), e.g. in parallel test runners

Test plan

  • npm test passes (96 runtime tests, 108 type tests across TS 5.8 / 5.9 / 6.0, type coverage 99.87%)
  • npm run check:knip — clean
  • Verify type: 'number' round-trips: parse → flags.count is number, not string
  • Verify alias rewriting: --colors resolves to flags.color
  • Verify unparseFlags round-trip: peowly(args).flags → unparseFlags → peowly gives identical flags

🤖 Generated with Claude Code

voxpelli and others added 4 commits March 27, 2026 15:03
peowly only supported 'string' and 'boolean' (the two types util.parseArgs()
natively understands). Consumers like Mocha need numeric flags for --retries
and --jobs without manual Number() coercion in application code.

A pre-parseArgs step remaps number flags to type:'string', and a post-parseArgs
coercion loop converts parsed string values back to numbers. Numeric defaults
are tracked separately and applied after coercion.

Note: negative numbers require '--flag=-N' syntax due to a parseArgs limitation
(it treats '--flag -N' as ambiguous with short flag clusters).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Allows declaring long-form aliases (e.g. --colors → --color) via an
`aliases` property on any flag definition. Aliases are rewritten in
argv before parseArgs sees them, supporting plain, =value, and multiple
alias forms. Opt-in alias display in help via `showAliasInHelp: true`.
Collision detection throws on duplicate or conflicting alias names.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Useful for rebuilding a CLI argv for child_process.spawn(), e.g.
in parallel test runners. Boolean true emits --flag, false is omitted,
strings/numbers emit --flag value, multiples emit one pair per element.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
index.js is auto-detected from package.json exports, so the explicit
entry was redundant. jq is used in test:tstyche to read the minimum
TypeScript version but is a system tool rather than an npm package.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@voxpelli voxpelli force-pushed the feat/number-aliases-unparse branch from 7b3bf59 to 7ef8b55 Compare March 27, 2026 16:26
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