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
In other words, I want to always call path.resolve() on the value. I know I could do this myself after accessing argv but it would be easier to keep this logic in the same place as the option definition. Is there a way to do this already?
Could this be hooked into validation? For example, throwing from your coercer could trigger the typical validation failure handling (or, more robust: cb(err, res) or a promise). Coercing is desirable for keeping the definitions together, but in itself it’s nothing one couldn’t do after the parsing is complete; however, making that coercion hook into yargs’ validation would permit exiting on the first invalid argument, which is something I don’t think is currently possible.
Activity
bcoe commentedon Jul 3, 2016
@kumar303 I think I've heard of this option referred to as
coercionby other folks:#191
I like this idea, and would love to add it.
bathos commentedon Jul 18, 2016
Could this be hooked into validation? For example, throwing from your coercer could trigger the typical validation failure handling (or, more robust:
cb(err, res)or a promise). Coercing is desirable for keeping the definitions together, but in itself it’s nothing one couldn’t do after the parsing is complete; however, making that coercion hook into yargs’ validation would permit exiting on the first invalid argument, which is something I don’t think is currently possible.bcoe commentedon Aug 14, 2016
@kumar303 @bathos
[email protected]has introduced the concept ofcoercion, which should address this feature request:https://github.com/yargs/yargs#coercekey-fn
Give this a spin:
npm cache clear; npm i yargs@next@bathos if you throw an exception from within the coercion function, it will be handled by yargs' validation logic.