Closed codefoster closed 4 years ago
Sorry, no plans for validation. https://github.com/75lb/command-line-args/wiki/Validation#why-is-validation-not-built-into-the-module
Thanks. I like the single purpose principle, so this is good. It leaves room for a compatible (uses the same schema for command options) package that does do validation. In the mean time, I baked it into my app. I add required
and validationPattern
(a regex) to each of the options and then run this...
// check required arguments
options.filter(o => o.required && !values[o.name])
.forEach(o => validationMessages.push(`Missing ${o.name} argument`));
// check validation patterns
options.filter(o => o.validationPattern && !o.validationPattern.test(values[o.name]))
.forEach(o => validationMessages.push(`Value for ${o.name} argument is not valid`));
Looks good to me!
I'd love to be able to add
required: true
to an argument option to havecommand-line-args
validate that the user passed it in.