Skip to content

fix: replace every $1 in demandCommand min/max messages#2556

Open
patrickwehbe wants to merge 1 commit into
yargs:mainfrom
patrickwehbe:fix-demandcommand-message-templating
Open

fix: replace every $1 in demandCommand min/max messages#2556
patrickwehbe wants to merge 1 commit into
yargs:mainfrom
patrickwehbe:fix-demandcommand-message-templating

Conversation

@patrickwehbe

@patrickwehbe patrickwehbe commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

The custom minMsg/maxMsg templating in demandCommand replaces $0 with a global regex but $1 without one, so only the first $1 in a message is substituted and any later $1 is left as a literal.

The docs say otherwise (docs/api.md): "every instance of $1 will be replaced with the expected value". So the $1 replace should be global to match $0 and the documented behavior.

Before, with 'got $0 ($0), max $1 ($1)':

got 3 (3), max 2 ($1)

After:

got 3 (3), max 2 (2)

Changed both the min and max branches in lib/validation.ts and added a test covering repeated tokens. Full suite passes locally.

The minMsg/maxMsg templating replaced $0 with a global regex but $1
without one, so only the first $1 in a custom message was substituted
and any later $1 was left literal. The docs state every instance of
$1 is replaced with the expected count, so make the $1 replace global
to match $0 and the documented behavior.
@shadowspawn

Copy link
Copy Markdown
Member

(I will rerun tests after #2554 lands to stabilise build.)

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.

2 participants