-
Notifications
You must be signed in to change notification settings - Fork 23
Open
Description
Boolean options are considering any value as true. For example, let's consider an application that runs scripts by default and the user can filter the script to run:
{
alias: { scriptFile: '--script-file' }, // filter the script files to run
boolean: [ 'run' ], // indented to apply `--no-run` to avoid running script files
default: { run: true }
}A user then make a mistake an type the following for filtering the script to run:
node example.js --run=my-script.jsThat only gives { "_": [], "run": true }, that is, when I validate run for reporting the invalid syntax, its value is true and getopts lacks the incorrect value (my-script.js) - so I can't detect and report it. That makes the application run without the user knowing about the problem (and the filter will not be applied...).
Wouldn't be a better approach to assign the received value, in order to be possible to validate it? It would still pass an if test (as true).
Metadata
Metadata
Assignees
Labels
No labels