Skip to content

Commit

Permalink
fix boolean default setting
Browse files Browse the repository at this point in the history
  • Loading branch information
juergba committed Jun 15, 2019
1 parent 7e01a2c commit d9d6fbd
Showing 1 changed file with 2 additions and 24 deletions.
26 changes: 2 additions & 24 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,14 +132,6 @@ function parse (args, opts) {
})

var argv = { _: [] }

Object.keys(flags.bools).forEach(function (key) {
if (Object.prototype.hasOwnProperty.call(defaults, key)) {
setArg(key, defaults[key])
setDefaulted(key)
}
})

var notFlags = []

for (var i = 0; i < args.length; i++) {
Expand Down Expand Up @@ -406,8 +398,6 @@ function parse (args, opts) {
}

function setArg (key, val) {
unsetDefaulted(key)

if (/-/.test(key) && configuration['camel-case-expansion']) {
var alias = key.split('.').map(function (prop) {
return camelCase(prop)
Expand Down Expand Up @@ -704,7 +694,7 @@ function parse (args, opts) {
}
} else if (o[key] === undefined && isTypeArray) {
o[key] = isValueArray ? value : [value]
} else if (duplicate && !(o[key] === undefined || checkAllAliases(key, flags.bools) || checkAllAliases(keys.join('.'), flags.bools) || checkAllAliases(key, flags.counts))) {
} else if (duplicate && !(o[key] === undefined || checkAllAliases(key, flags.counts))) {
o[key] = [ o[key], value ]
} else {
o[key] = value
Expand Down Expand Up @@ -762,19 +752,7 @@ function parse (args, opts) {
return isSet
}

function setDefaulted (key) {
[].concat(flags.aliases[key] || [], key).forEach(function (k) {
flags.defaulted[k] = true
})
}

function unsetDefaulted (key) {
[].concat(flags.aliases[key] || [], key).forEach(function (k) {
delete flags.defaulted[k]
})
}

// make a best effor to pick a default value
// make a best effort to pick a default value
// for an option based on name and type.
function defaultValue (key) {
if (!checkAllAliases(key, flags.bools) &&
Expand Down

0 comments on commit d9d6fbd

Please sign in to comment.