History of 2020-05-24 Two parameters and at least one required in yargs

2020-05-24
08:17 UTC Revision 1 . . . . mborkI happen to write shell scripts in Node.JS quite often. They usually consume some kind of command-line agruments, and my library of choice to parse them is yargs. Recently, I had a situation where there were two parameters and it was required that one of them is given. A bit surprisingly, yargs does not seem to have an option requiredAlternative or something that says “of the following two parameters, at least one must be given” (it has a conflicts method and option, either of which can be used to say “of these two parameters, at most one may be given”, though). Happily, there is a simple way to enforce such a requiement due to the quite general “check” method.