initial
This commit is contained in:
41
node_modules/command-line-args/lib/output-grouped.js
generated
vendored
Normal file
41
node_modules/command-line-args/lib/output-grouped.js
generated
vendored
Normal file
@ -0,0 +1,41 @@
|
||||
'use strict'
|
||||
const Output = require('./output')
|
||||
|
||||
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
|
||||
const grouped = {
|
||||
_all: superOutput
|
||||
}
|
||||
if (unknown && unknown.length) grouped._unknown = unknown
|
||||
|
||||
this.definitions.whereGrouped().forEach(def => {
|
||||
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][name] = outputValue
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
this.definitions.whereNotGrouped().forEach(def => {
|
||||
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[name] = outputValue
|
||||
}
|
||||
})
|
||||
return grouped
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = GroupedOutput
|
Reference in New Issue
Block a user