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
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 runboolean: ['run'],// indented to apply `--no-run` to avoid running script filesdefault: {run: true}}
A user then make a mistake an type the following for filtering the script to run:
node example.js --run=my-script.js
That 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).
The text was updated successfully, but these errors were encountered:
@thiagodp Hmm, yeah, it might be more useful to assign the value to the option and leave further parsing to the user in the case of boolean flags, that way users can throw an error or do whatever they want. Parsing rules wouldn't change, e.g., we'd still handle immediately adjacent non-flag arguments as operands (instead of values).
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:A user then make a mistake an type the following for filtering the script to run:
That only gives
{ "_": [], "run": true }
, that is, when I validaterun
for reporting the invalid syntax, its value istrue
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 (astrue
).The text was updated successfully, but these errors were encountered: