Open ajafff opened 6 years ago
Hi, thanks for this feature request. I am quite into the second solution (though I might prefer peek
and consume
), it looks like a more elegant way consuming options while giving developers more flexibility.
Will come out with some refactoring ideas later.
While trying to port my CLI, I noticed there is no way to declare options that may not consume the next argument if not necessary.
A popular example are TypeScript's compilerOptions:
In my use case this is not limited to a switch option (boolean value). It's actually an optional boolean or number:
I can think of 2 possible solutions:
Add
optional
flagIf
optional
is true and validating the argument using thevalidator
fails, do not consume the argument and use the default value instead.Add
parse
functionIf a
parse
function is provided, this function is responsible for consuming the arguments, parsing and converting the value. By callingconsume()
more than once the parser may consume 0..n of the remaining arguments.validators
are still executed after parsing. That means errors about invalid option values can be reported. That's not possible with theoptional
proposal.