Skip to content

Commit

Permalink
Fixed 75lb#78: camelCase now works on groups
Browse files Browse the repository at this point in the history
  • Loading branch information
75lb committed Feb 7, 2018
1 parent 11e9fc2 commit 087e88d
Show file tree
Hide file tree
Showing 8 changed files with 212 additions and 191 deletions.
4 changes: 1 addition & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,5 @@ function commandLineArgs (optionDefinitions, options) {
}
}

const result = output.toObject({ skipUnknown: !options.partial })
const optionUtil = require('./lib/option-util')
return options.camelCase ? optionUtil.camelCaseObject(result) : result
return output.toObject({ skipUnknown: !options.partial, camelCase: options.camelCase })
}
15 changes: 0 additions & 15 deletions lib/option-util.js

This file was deleted.

12 changes: 8 additions & 4 deletions lib/output-grouped.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ class GroupedOutput extends Output {
toObject (options) {
const arrayify = require('array-back')
const t = require('typical')
const camelCase = require('lodash.camelcase')
const superOutputNoCamel = super.toObject({ skipUnknown: options.skipUnknown })
const superOutput = super.toObject(options)
const unknown = superOutput._unknown
delete superOutput._unknown
Expand All @@ -14,20 +16,22 @@ class GroupedOutput extends Output {
if (unknown && unknown.length) grouped._unknown = unknown

this.definitions.whereGrouped().forEach(def => {
const outputValue = superOutput[def.name]
const name = options.camelCase ? camelCase(def.name) : def.name
const outputValue = superOutputNoCamel[def.name]
for (const groupName of arrayify(def.group)) {
grouped[groupName] = grouped[groupName] || {}
if (t.isDefined(outputValue)) {
grouped[groupName][def.name] = outputValue
grouped[groupName][name] = outputValue
}
}
})

this.definitions.whereNotGrouped().forEach(def => {
const outputValue = superOutput[def.name]
const name = options.camelCase ? camelCase(def.name) : def.name
const outputValue = superOutputNoCamel[def.name]
if (t.isDefined(outputValue)) {
if (!grouped._none) grouped._none = {}
grouped._none[def.name] = outputValue
grouped._none[name] = outputValue
}
})
return grouped
Expand Down
3 changes: 2 additions & 1 deletion lib/output.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@ class Output extends Map {
}

toObject (options) {
const camelCase = require('lodash.camelcase')
options = options || {}
const output = {}
for (const item of this) {
const name = item[0]
const name = options.camelCase && item[0] !== '_unknown' ? camelCase(item[0]) : item[0]
const option = item[1]
if (name === '_unknown' && !option.get().length) continue
output[name] = option.get()
Expand Down
200 changes: 87 additions & 113 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 087e88d

Please sign in to comment.