Multiple calls to choices should not create duplicate choices for same option
Author: ogallagherCreated Mar 1, 2025Updated Sep 13, 2026
Labelsdocs
Environment details
The documentation for choices(key: string, values: any[]) says:
If this method is called multiple times, all enumerated values will be merged together.
I think that implies that if I call choices('color', ['red', 'green', 'blue'])
and then choices('color', ['blue', 'rainbow']),
then the resulting choices for opt color should be the superset of the two lists provided, without duplicates.
['red', 'green', 'blue', 'rainbow']Instead, I am seeing duplicate choices.
const argParser = require('yargs')()
argParser.option('color')
argParser.choices('color', ['red', 'green', 'blue'])
console.log(await argParser.getHelp())
`
Options:
--help Show help [boolean]
--version Show version number [boolean]
--color [choices: "red", "green", "blue"]
`
argParser.choices('color', ['red', 'green', 'blue', 'rainbow'])
console.log(await argParser.getHelp())
`
Options:
--help Show help [boolean]
--version Show version number [boolean]
--color [choices: "red", "green", "blue", "red", "green", "blue", "rainbow"]
`I request that the merge behavior of choices match the behavior of Set equality for preventing duplicates.
Source: yargs/yargs