This came up while implementing the --debug
flag for AVA.
Basically, there are two ways to use the debug flag:
# default port (5858)
ava --debug test.js
# specific port
ava --debug=1234 test.js
# not allowed - this won't work
ava --debug 1234 test.js
The reason you can't use the last one is because it's ambiguous whether you meant "run two test files with the default port" or "run one file with port 1234".
When you specify the flag as boolean:
meow(help, {
boolean: [
'debug'
]
});
You get true
or false
regardless. However you must specify it as a boolean, or this:
ava --debug test.js
To be interpreted as:
{
flags: {
debug: 'test.js'
}
}
My solution was to set debug
up as a boolean
, then if I got true
, reparse argv to find the port
I think it might be interesting to allow this:
meow(helper, {
booleanish: {
debug: {
true: 5858,
false: false,
parse: function (value) {
value = parseInt(value, 10);
if (isNaN(value)) {
throw new Error('must be a number');
}
return value;
}
}
}
});
The basic usage of the booleanish
option is:
true
: What gets returned if it is used as a boolean flag --debug
false
: What gets returned if no flag appears (or --no-debug
is used).parse
: If they use the --debug=XXX
- this function is used to parse the XXX
part. It can throw an Error for invalid values, and meow
should print the Error message, and exit.This would greatly ease the creation of dual purpose flags that can be used either as simple booleans, or be supplied with a config value.
Pay now to fund the work behind this issue.
Get updates on progress being made.
Maintainer is rewarded once the issue is completed.
You're funding impactful open source efforts
You want to contribute to this effort
You want to get funding like this too