Yargs sadly fails to support the super-common idiom of "subset of allowed values". Setting the "choices" array for an option breaks the "array" functionality: the value is still returned as array, but only contains the first element specified on the command line.
I tried to reproduce it. But yargs worked for me. Both app -o a -o b and app -o a b printed o: ['a', 'b']. The first approach also worked with typed-cli. Can you provide with a code sample of what you mean exactly?
Turns out it was not choices that was the culprit but requiresArg. It's an embarrasing, long-standing bug in yargs. I made a PR to revert the commit that introduced it.
Yargs sadly fails to support the super-common idiom of "subset of allowed values". Setting the "choices" array for an option breaks the "array" functionality: the value is still returned as array, but only contains the first element specified on the command line.
I tried to reproduce it. But yargs worked for me. Both
app -o a -o b
andapp -o a b
printedo: ['a', 'b']
. The first approach also worked withtyped-cli
. Can you provide with a code sample of what you mean exactly?Turns out it was not
choices
that was the culprit butrequiresArg
. It's an embarrasing, long-standing bug in yargs. I made a PR to revert the commit that introduced it.I got TypeError using
choices
witharray
in latest version 17.6.2