Skip to content

Commit

Permalink
[Refactor] combine aliasIsBoolean and external code checks into sel…
Browse files Browse the repository at this point in the history
…f-contained `isBooleanKey`
  • Loading branch information
shadowspawn authored and ljharb committed Apr 8, 2023
1 parent 093bc85 commit 84316a9
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,13 @@ module.exports = function (args, opts) {

var aliases = {};

function aliasIsBoolean(key) {
function isBooleanKey(key) {
if (flags.bools[key]) {
return true;
}
if (!aliases[key]) {
return false;
}
return aliases[key].some(function (x) {
return flags.bools[x];
});
Expand Down Expand Up @@ -165,9 +171,8 @@ module.exports = function (args, opts) {
if (
next !== undefined
&& !(/^(-|--)[^-]/).test(next)
&& !flags.bools[key]
&& !isBooleanKey(key)
&& !flags.allBools
&& (aliases[key] ? !aliasIsBoolean(key) : true)
) {
setArg(key, next, arg);
i += 1;
Expand Down Expand Up @@ -218,8 +223,7 @@ module.exports = function (args, opts) {
if (
args[i + 1]
&& !(/^(-|--)[^-]/).test(args[i + 1])
&& !flags.bools[key]
&& (aliases[key] ? !aliasIsBoolean(key) : true)
&& !isBooleanKey(key)
) {
setArg(key, args[i + 1], arg);
i += 1;
Expand Down

0 comments on commit 84316a9

Please sign in to comment.