It looks like there is no easy way to override error message for required positional argument:
https://github.com/yargs/yargs/blob/16ee006eb1597427c8a964b0f69d7b3ce8407ca2/lib/validation.js#L61
It would be nice if there was a mecanism similar to demandOption where a custom error string could be provided.
@proppy No, I'm afraid there is no way to do it at the moment.
@bcoe I think we should merge the required positional and required options validation. Not only would we simplify the validation code (which is my main interest here, to be honest :-)), but we would also allow the use of .demandOption for positionals, as is required here.
I will try to have a look at this once lib/command and yargs are tsified (doing both at the same time would be dangerous).
Note that it would be a breaking change, as it would have (positive) impacts on error and help messages for commands using positionals.
This seems like a reasonable feature request.
@proppy, I think I'm not 100% sure what you're referring to with _"we should merge the required positional and required options validation."_, this might be a proposal I haven't read yet? I agree that we should land the TypeScript conversion first.
@bcoe I was thinking about:
demandOption property for positional options (with a check that it can be truthy only if the positional is required).addHandler('cmd <req> [opt]'... calling .positional('req', { demandOption: true }) and .positional('opt', {})positionalCount() as required positional presence would already be checked with other required optionscmdToParseOptions() as most of its code would no longer be necessaryAs a side effect .demandOption('req', message) would work too for positionals, and should answer @proppy 's needs.
Most helpful comment
@bcoe I was thinking about:
demandOptionproperty for positional options (with a check that it can be truthy only if the positional is required).addHandler('cmd <req> [opt]'...calling.positional('req', { demandOption: true })and.positional('opt', {})positionalCount()as required positional presence would already be checked with other required optionscmdToParseOptions()as most of its code would no longer be necessaryAs a side effect
.demandOption('req', message)would work too for positionals, and should answer @proppy 's needs.