Skip to content

Commit

Permalink
log defaulted flags
Browse files Browse the repository at this point in the history
  • Loading branch information
juergba committed Oct 29, 2019
1 parent f9a3e4e commit 14b8fc9
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ function parse (args, opts) {
var notFlagsOption = configuration['populate--']
var notFlagsArgv = notFlagsOption ? '--' : '_'
var newAliases = {}
var defaulted = {}
// allow a i18n handler to be passed in, default to a fake one (util.format).
var __ = opts.__ || util.format
var error = null
Expand Down Expand Up @@ -317,7 +318,7 @@ function parse (args, opts) {
applyEnvVars(argv, false)
setConfig(argv)
setConfigObjects()
applyDefaultsAndAliases(argv, flags.aliases, defaults)
applyDefaultsAndAliases(argv, flags.aliases, defaults, true)
applyCoercions(argv)
if (configuration['set-placeholder-key']) setPlaceholderKeys(argv)

Expand Down Expand Up @@ -627,10 +628,11 @@ function parse (args, opts) {
return argv
}

function applyDefaultsAndAliases (obj, aliases, defaults) {
function applyDefaultsAndAliases (obj, aliases, defaults, log = false) {
Object.keys(defaults).forEach(function (key) {
if (!hasKey(obj, key.split('.'))) {
setKey(obj, key.split('.'), defaults[key])
if (log) defaulted[key] = true

;(aliases[key] || []).forEach(function (x) {
if (hasKey(obj, x.split('.'))) return
Expand Down Expand Up @@ -895,6 +897,7 @@ function parse (args, opts) {
error: error,
aliases: flags.aliases,
newAliases: newAliases,
defaulted: defaulted,
configuration: configuration
}
}
Expand Down

0 comments on commit 14b8fc9

Please sign in to comment.