3 const isPlainObject = require('is-plain-obj');
4 const arrify = require('arrify');
6 const push = (obj, prop, value) => {
11 obj[prop].push(value);
14 const insert = (obj, prop, key, value) => {
19 obj[prop][key] = value;
22 const passthroughOptions = ['stopEarly', 'unknown', '--'];
24 module.exports = options => {
25 options = options || {};
29 passthroughOptions.forEach(key => {
31 result[key] = options[key];
35 Object.keys(options).forEach(key => {
36 let value = options[key];
38 if (key === 'arguments') {
42 // If short form is used
43 // convert it to long form
44 // e.g. { 'name': 'string' }
45 if (typeof value === 'string') {
46 value = {type: value};
49 if (isPlainObject(value)) {
53 const type = props.type;
55 if (type === 'string') {
56 push(result, 'string', key);
59 if (type === 'boolean') {
60 push(result, 'boolean', key);
64 const aliases = arrify(props.alias);
66 aliases.forEach(alias => {
67 insert(result, 'alias', alias, key);
70 if ({}.hasOwnProperty.call(props, 'default')) {
71 insert(result, 'default', key, props.default);