You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If a non-flag option - unless true or false - follows key in process.argv, that string won’t get set as the value of key.
This means that if a CLI defines an option as a boolean, it isn't currently possible to later change that option to support more choices than true or false without creating a breaking change for the CLI's interface.
If the choices option were handled already in the parser, it'd be possible to (optionally?) allow similar behaviour for it:
require('yargs-parser')('--foo bar',{choices: ['true','false','maybe'],// not a current parser optiondefault: {foo: 'maybe'}})>{_: ['bar'],foo: 'maybe'}
A similar result could also be achieved if the coerce function could indicate that the given value should not be consumed for the current key, but parsed independently:
require('yargs-parser')('--foo bar',{coerce: {foo(value){if(['true','false','maybe'].includes(value)returnvaluethis.doNotEat()// not currently defined; could also be an argumentreturn'maybe'}}})>{_: ['bar'],foo: 'maybe'}
The text was updated successfully, but these errors were encountered:
Related: yargs/yargs#1599
Boolean options have this special property:
This means that if a CLI defines an option as a boolean, it isn't currently possible to later change that option to support more choices than
true
orfalse
without creating a breaking change for the CLI's interface.In other words, this happens currently:
If the
choices
option were handled already in the parser, it'd be possible to (optionally?) allow similar behaviour for it:A similar result could also be achieved if the
coerce
function could indicate that the givenvalue
should not be consumed for the currentkey
, but parsed independently:The text was updated successfully, but these errors were encountered: