Change parse() output to always use long flag names as keys
This commit is contained in:
parent
f43915c735
commit
c3166ef17b
9
opter.js
9
opter.js
|
|
@ -40,6 +40,9 @@ module.exports = class Opter {
|
||||||
parse(argv) {
|
parse(argv) {
|
||||||
this.userOptions = argvToObject(argv);
|
this.userOptions = argvToObject(argv);
|
||||||
|
|
||||||
|
// collect user opts with the long names as keys, for output
|
||||||
|
let normalizedUserOptions = {};
|
||||||
|
|
||||||
Object.keys(this.definedOptions).forEach(longName => {
|
Object.keys(this.definedOptions).forEach(longName => {
|
||||||
let shortName = this.synonyms[longName];
|
let shortName = this.synonyms[longName];
|
||||||
let reqs = this.definedOptions[longName];
|
let reqs = this.definedOptions[longName];
|
||||||
|
|
@ -52,6 +55,10 @@ module.exports = class Opter {
|
||||||
if (typeof this.userOptions[longName] === 'object') { userArgs = this.userOptions[longName]; }
|
if (typeof this.userOptions[longName] === 'object') { userArgs = this.userOptions[longName]; }
|
||||||
if (typeof this.userOptions[shortName] === 'object') { userArgs = this.userOptions[shortName]; }
|
if (typeof this.userOptions[shortName] === 'object') { userArgs = this.userOptions[shortName]; }
|
||||||
|
|
||||||
|
if (provided) {
|
||||||
|
normalizedUserOptions[longName] = typeof userArgs === 'object' ? userArgs : true;
|
||||||
|
}
|
||||||
|
|
||||||
/* Check that required options are provided */
|
/* Check that required options are provided */
|
||||||
if (reqs.required && !provided) {
|
if (reqs.required && !provided) {
|
||||||
throw new Error(`Missing required option '${longName}'`);
|
throw new Error(`Missing required option '${longName}'`);
|
||||||
|
|
@ -70,7 +77,7 @@ module.exports = class Opter {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
return this.userOptions;
|
return normalizedUserOptions;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue