Comparing version 6.3.12 to 6.4.0
@@ -263,2 +263,13 @@ 'use strict'; | ||
}; | ||
exports.setByType = (obj, transforms) => { | ||
for (const key of Object.keys(transforms)) { | ||
const transform = transforms[key]; | ||
if (transform.shouldTransform) { | ||
obj[key] = Array.prototype.concat.call([], obj[key]); | ||
if (typeof transform.transformFunction === 'function') { | ||
obj[key] = obj[key].map(transform.transformFunction); | ||
} | ||
} | ||
} | ||
}; | ||
}); | ||
@@ -274,2 +285,3 @@ | ||
var utils_7 = utils.setDotProp; | ||
var utils_8 = utils.setByType; | ||
@@ -727,10 +739,18 @@ var Option_1 = createCommonjsModule(function (module, exports) { | ||
: this.globalCommand.config.ignoreOptionDefaultValue; | ||
if (!ignoreDefault) { | ||
for (const cliOption of cliOptions) { | ||
if (cliOption.config.default !== undefined) { | ||
for (const name of cliOption.names) { | ||
options[name] = cliOption.config.default; | ||
} | ||
let transforms = Object.create(null); | ||
for (const cliOption of cliOptions) { | ||
if (!ignoreDefault && cliOption.config.default !== undefined) { | ||
for (const name of cliOption.names) { | ||
options[name] = cliOption.config.default; | ||
} | ||
} | ||
// If options type is defined | ||
if (Array.isArray(cliOption.config.type)) { | ||
if (transforms[cliOption.name] === undefined) { | ||
transforms[cliOption.name] = Object.create(null); | ||
transforms[cliOption.name]['shouldTransform'] = true; | ||
transforms[cliOption.name]['transformFunction'] = | ||
cliOption.config.type[0]; | ||
} | ||
} | ||
} | ||
@@ -743,2 +763,3 @@ // Camelcase option names and set dot nested option values | ||
utils.setDotProp(options, keys, parsed[key]); | ||
utils.setByType(options, transforms); | ||
} | ||
@@ -745,0 +766,0 @@ return { |
{ | ||
"name": "cac", | ||
"version": "6.3.12", | ||
"version": "6.4.0", | ||
"description": "Simple yet powerful framework for building command-line apps.", | ||
@@ -5,0 +5,0 @@ "repository": { |
@@ -100,3 +100,4 @@ <img width="945" alt="2017-07-26 9 27 05" src="https://user-images.githubusercontent.com/8784712/28623641-373450f4-7249-11e7-854d-1b076dab274d.png"> | ||
cli.help() | ||
// Display version number when `-h` or `--help` appears | ||
// Display version number when `-v` or `--version` appears | ||
// It's also used in help message | ||
cli.version('0.0.0') | ||
@@ -134,5 +135,5 @@ | ||
When using brackets in command name, angled brackets indicate required command arguments, while sqaure bracket indicate optional arguments. | ||
When using brackets in command name, angled brackets indicate required command arguments, while square bracket indicate optional arguments. | ||
When using brackets in option name, angled brackets indicate that a string / number value is required, while sqaure bracket indicate that the value can also be `true`. | ||
When using brackets in option name, angled brackets indicate that a string / number value is required, while square bracket indicate that the value can also be `true`. | ||
@@ -314,2 +315,3 @@ ```js | ||
- `config.default`: Default value for the option. | ||
- `config.type`: `any[]` When set to `[]`, the option value returns an array type. You can also use a conversion function such as `[String]`, which will invoke the option value with `String`. | ||
@@ -316,0 +318,0 @@ #### cli.parse(argv?) |
interface OptionConfig { | ||
default?: any; | ||
type?: any[]; | ||
} | ||
@@ -4,0 +5,0 @@ export default class Option { |
@@ -21,2 +21,7 @@ import Option from './Option'; | ||
}, keys: string[], val: any) => void; | ||
export declare const setByType: (obj: { | ||
[k: string]: any; | ||
}, transforms: { | ||
[k: string]: any; | ||
}) => void; | ||
export {}; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
48682
990
467