| 
									
										
										
										
											2020-03-09 21:18:34 +08:00
										 |  |  | /* | 
					
						
							|  |  |  | 	MIT License http://www.opensource.org/licenses/mit-license.php
 | 
					
						
							|  |  |  | 	Author Tobias Koppers @sokra | 
					
						
							|  |  |  | */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | "use strict"; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-10 20:30:18 +08:00
										 |  |  | const path = require("path"); | 
					
						
							| 
									
										
										
										
											2020-03-26 23:45:49 +08:00
										 |  |  | const webpackSchema = require("../schemas/WebpackOptions.json"); | 
					
						
							| 
									
										
										
										
											2020-03-09 21:18:34 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-10 20:30:18 +08:00
										 |  |  | // TODO add originPath to PathItem for better errors
 | 
					
						
							|  |  |  | /** | 
					
						
							|  |  |  |  * @typedef {Object} PathItem | 
					
						
							|  |  |  |  * @property {any} schema the part of the schema | 
					
						
							|  |  |  |  * @property {string} path the path in the config | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-21 21:01:38 +08:00
										 |  |  | /** @typedef {"unknown-argument" | "unexpected-non-array-in-path" | "unexpected-non-object-in-path" | "multiple-values-unexpected" | "invalid-value"} ProblemType */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-10 20:30:18 +08:00
										 |  |  | /** | 
					
						
							|  |  |  |  * @typedef {Object} Problem | 
					
						
							| 
									
										
										
										
											2020-03-21 21:01:38 +08:00
										 |  |  |  * @property {ProblemType} type | 
					
						
							| 
									
										
										
										
											2020-03-10 20:30:18 +08:00
										 |  |  |  * @property {string} path | 
					
						
							| 
									
										
										
										
											2020-03-26 04:11:46 +08:00
										 |  |  |  * @property {string} argument | 
					
						
							|  |  |  |  * @property {any=} value | 
					
						
							|  |  |  |  * @property {number=} index | 
					
						
							| 
									
										
										
										
											2020-03-26 23:41:50 +08:00
										 |  |  |  * @property {string=} expected | 
					
						
							| 
									
										
										
										
											2020-03-10 20:30:18 +08:00
										 |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							| 
									
										
										
										
											2020-03-26 04:11:46 +08:00
										 |  |  |  * @typedef {Object} LocalProblem | 
					
						
							| 
									
										
										
										
											2020-03-21 21:01:38 +08:00
										 |  |  |  * @property {ProblemType} type | 
					
						
							| 
									
										
										
										
											2020-03-26 04:11:46 +08:00
										 |  |  |  * @property {string} path | 
					
						
							| 
									
										
										
										
											2020-03-26 23:41:50 +08:00
										 |  |  |  * @property {string=} expected | 
					
						
							| 
									
										
										
										
											2020-03-26 04:11:46 +08:00
										 |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							|  |  |  |  * @typedef {Object} ArgumentConfig | 
					
						
							| 
									
										
										
										
											2020-03-10 20:30:18 +08:00
										 |  |  |  * @property {string} description | 
					
						
							|  |  |  |  * @property {string} path | 
					
						
							| 
									
										
										
										
											2020-03-26 04:11:46 +08:00
										 |  |  |  * @property {boolean} multiple | 
					
						
							| 
									
										
										
										
											2020-03-26 18:37:42 +08:00
										 |  |  |  * @property {"enum"|"string"|"path"|"number"|"boolean"|"RegExp"|"reset"} type | 
					
						
							| 
									
										
										
										
											2020-03-26 04:11:46 +08:00
										 |  |  |  * @property {any[]=} values | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							|  |  |  |  * @typedef {Object} Argument | 
					
						
							|  |  |  |  * @property {string} description | 
					
						
							|  |  |  |  * @property {"string"|"number"|"boolean"} simpleType | 
					
						
							|  |  |  |  * @property {boolean} multiple | 
					
						
							|  |  |  |  * @property {ArgumentConfig[]} configs | 
					
						
							| 
									
										
										
										
											2020-03-10 20:30:18 +08:00
										 |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							| 
									
										
										
										
											2020-03-26 23:45:49 +08:00
										 |  |  |  * @param {any=} schema a json schema to create arguments for (by default webpack schema is used) | 
					
						
							| 
									
										
										
										
											2020-03-10 20:30:18 +08:00
										 |  |  |  * @returns {Record<string, Argument>} object of arguments | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2020-03-26 23:45:49 +08:00
										 |  |  | const getArguments = (schema = webpackSchema) => { | 
					
						
							| 
									
										
										
										
											2020-03-10 20:30:18 +08:00
										 |  |  | 	/** @type {Record<string, Argument>} */ | 
					
						
							| 
									
										
										
										
											2020-03-09 21:18:34 +08:00
										 |  |  | 	const flags = {}; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-09 23:24:04 +08:00
										 |  |  | 	const pathToArgumentName = input => { | 
					
						
							| 
									
										
										
										
											2020-03-09 21:18:34 +08:00
										 |  |  | 		return input | 
					
						
							| 
									
										
										
										
											2020-03-10 20:30:18 +08:00
										 |  |  | 			.replace(/\./g, "-") | 
					
						
							| 
									
										
										
										
											2020-03-25 18:36:33 +08:00
										 |  |  | 			.replace(/\[\]/g, "") | 
					
						
							| 
									
										
										
										
											2020-03-09 21:18:34 +08:00
										 |  |  | 			.replace( | 
					
						
							| 
									
										
										
										
											2020-08-16 18:29:28 +08:00
										 |  |  | 				/(\p{Uppercase_Letter}+|\p{Lowercase_Letter}|\d)(\p{Uppercase_Letter}+)/gu, | 
					
						
							| 
									
										
										
										
											2020-03-09 21:18:34 +08:00
										 |  |  | 				"$1-$2" | 
					
						
							|  |  |  | 			) | 
					
						
							| 
									
										
										
										
											2020-03-09 23:24:04 +08:00
										 |  |  | 			.replace(/-?[^\p{Uppercase_Letter}\p{Lowercase_Letter}\d]+/gu, "-") | 
					
						
							| 
									
										
										
										
											2020-03-09 21:18:34 +08:00
										 |  |  | 			.toLowerCase(); | 
					
						
							| 
									
										
										
										
											2020-03-09 23:24:04 +08:00
										 |  |  | 	}; | 
					
						
							| 
									
										
										
										
											2020-03-09 21:18:34 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-09 23:24:04 +08:00
										 |  |  | 	const getSchemaPart = path => { | 
					
						
							| 
									
										
										
										
											2020-03-09 21:18:34 +08:00
										 |  |  | 		const newPath = path.split("/"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		let schemaPart = schema; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		for (let i = 1; i < newPath.length; i++) { | 
					
						
							|  |  |  | 			const inner = schemaPart[newPath[i]]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			if (!inner) { | 
					
						
							|  |  |  | 				break; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			schemaPart = inner; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		return schemaPart; | 
					
						
							| 
									
										
										
										
											2020-03-09 23:24:04 +08:00
										 |  |  | 	}; | 
					
						
							| 
									
										
										
										
											2020-03-09 21:18:34 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-10 20:30:18 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * | 
					
						
							|  |  |  | 	 * @param {PathItem[]} path path in the schema | 
					
						
							|  |  |  | 	 * @returns {string | undefined} description | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2020-03-09 23:46:31 +08:00
										 |  |  | 	const getDescription = path => { | 
					
						
							|  |  |  | 		for (const { schema } of path) { | 
					
						
							|  |  |  | 			if (schema.cli && schema.cli.helper) continue; | 
					
						
							|  |  |  | 			if (schema.description) return schema.description; | 
					
						
							| 
									
										
										
										
											2020-03-09 23:24:04 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2020-03-09 21:18:34 +08:00
										 |  |  | 	}; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-10 20:30:18 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * | 
					
						
							| 
									
										
										
										
											2020-03-26 04:11:46 +08:00
										 |  |  | 	 * @param {any} schemaPart schema | 
					
						
							|  |  |  | 	 * @returns {Pick<ArgumentConfig, "type"|"values">} partial argument config | 
					
						
							| 
									
										
										
										
											2020-03-10 20:30:18 +08:00
										 |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2020-03-26 04:11:46 +08:00
										 |  |  | 	const schemaToArgumentConfig = schemaPart => { | 
					
						
							| 
									
										
										
										
											2020-03-10 20:30:18 +08:00
										 |  |  | 		if (schemaPart.enum) { | 
					
						
							| 
									
										
										
										
											2020-03-26 04:11:46 +08:00
										 |  |  | 			return { | 
					
						
							|  |  |  | 				type: "enum", | 
					
						
							|  |  |  | 				values: schemaPart.enum | 
					
						
							|  |  |  | 			}; | 
					
						
							| 
									
										
										
										
											2020-03-10 20:30:18 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 		switch (schemaPart.type) { | 
					
						
							|  |  |  | 			case "number": | 
					
						
							| 
									
										
										
										
											2020-03-26 04:11:46 +08:00
										 |  |  | 				return { | 
					
						
							|  |  |  | 					type: "number" | 
					
						
							|  |  |  | 				}; | 
					
						
							| 
									
										
										
										
											2020-03-10 20:30:18 +08:00
										 |  |  | 			case "string": | 
					
						
							| 
									
										
										
										
											2020-03-26 04:11:46 +08:00
										 |  |  | 				return { | 
					
						
							| 
									
										
										
										
											2020-03-26 06:27:55 +08:00
										 |  |  | 					type: schemaPart.absolutePath ? "path" : "string" | 
					
						
							| 
									
										
										
										
											2020-03-26 04:11:46 +08:00
										 |  |  | 				}; | 
					
						
							| 
									
										
										
										
											2020-03-10 20:30:18 +08:00
										 |  |  | 			case "boolean": | 
					
						
							| 
									
										
										
										
											2020-03-25 18:36:33 +08:00
										 |  |  | 				return { | 
					
						
							| 
									
										
										
										
											2020-03-26 04:11:46 +08:00
										 |  |  | 					type: "boolean" | 
					
						
							| 
									
										
										
										
											2020-03-25 18:36:33 +08:00
										 |  |  | 				}; | 
					
						
							| 
									
										
										
										
											2020-03-10 20:30:18 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2020-03-26 04:11:46 +08:00
										 |  |  | 		if (schemaPart.instanceof === "RegExp") { | 
					
						
							|  |  |  | 			return { | 
					
						
							|  |  |  | 				type: "RegExp" | 
					
						
							|  |  |  | 			}; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		return undefined; | 
					
						
							| 
									
										
										
										
											2020-03-10 20:30:18 +08:00
										 |  |  | 	}; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {PathItem[]} path path in the schema | 
					
						
							|  |  |  | 	 * @returns {void} | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	const addResetFlag = path => { | 
					
						
							| 
									
										
										
										
											2020-03-26 18:37:42 +08:00
										 |  |  | 		const schemaPath = path[0].path; | 
					
						
							|  |  |  | 		const name = pathToArgumentName(`${schemaPath}.reset`); | 
					
						
							| 
									
										
										
										
											2020-03-10 20:30:18 +08:00
										 |  |  | 		const description = getDescription(path); | 
					
						
							|  |  |  | 		flags[name] = { | 
					
						
							| 
									
										
										
										
											2020-03-26 04:11:46 +08:00
										 |  |  | 			configs: [ | 
					
						
							|  |  |  | 				{ | 
					
						
							| 
									
										
										
										
											2020-03-26 18:37:42 +08:00
										 |  |  | 					type: "reset", | 
					
						
							| 
									
										
										
										
											2020-03-26 04:11:46 +08:00
										 |  |  | 					multiple: false, | 
					
						
							| 
									
										
										
										
											2021-06-18 18:33:01 +08:00
										 |  |  | 					description: `Clear all items provided in '${schemaPath}' configuration. ${description}`, | 
					
						
							| 
									
										
										
										
											2020-03-26 04:11:46 +08:00
										 |  |  | 					path: schemaPath | 
					
						
							| 
									
										
										
										
											2020-03-10 20:30:18 +08:00
										 |  |  | 				} | 
					
						
							| 
									
										
										
										
											2020-03-26 04:11:46 +08:00
										 |  |  | 			], | 
					
						
							|  |  |  | 			description: undefined, | 
					
						
							|  |  |  | 			simpleType: undefined, | 
					
						
							|  |  |  | 			multiple: undefined | 
					
						
							| 
									
										
										
										
											2020-03-10 20:30:18 +08:00
										 |  |  | 		}; | 
					
						
							|  |  |  | 	}; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/** | 
					
						
							|  |  |  | 	 * @param {PathItem[]} path full path in schema | 
					
						
							|  |  |  | 	 * @param {boolean} multiple inside of an array | 
					
						
							|  |  |  | 	 * @returns {number} number of arguments added | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2020-03-09 23:46:31 +08:00
										 |  |  | 	const addFlag = (path, multiple) => { | 
					
						
							| 
									
										
										
										
											2020-03-26 04:11:46 +08:00
										 |  |  | 		const argConfigBase = schemaToArgumentConfig(path[0].schema); | 
					
						
							|  |  |  | 		if (!argConfigBase) return 0; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-09 23:46:31 +08:00
										 |  |  | 		const name = pathToArgumentName(path[0].path); | 
					
						
							| 
									
										
										
										
											2020-03-26 04:11:46 +08:00
										 |  |  | 		/** @type {ArgumentConfig} */ | 
					
						
							|  |  |  | 		const argConfig = { | 
					
						
							|  |  |  | 			...argConfigBase, | 
					
						
							|  |  |  | 			multiple, | 
					
						
							|  |  |  | 			description: getDescription(path), | 
					
						
							|  |  |  | 			path: path[0].path | 
					
						
							|  |  |  | 		}; | 
					
						
							| 
									
										
										
										
											2020-03-09 21:18:34 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		if (!flags[name]) { | 
					
						
							|  |  |  | 			flags[name] = { | 
					
						
							| 
									
										
										
										
											2020-03-26 04:11:46 +08:00
										 |  |  | 				configs: [], | 
					
						
							|  |  |  | 				description: undefined, | 
					
						
							|  |  |  | 				simpleType: undefined, | 
					
						
							|  |  |  | 				multiple: undefined | 
					
						
							| 
									
										
										
										
											2020-03-09 21:18:34 +08:00
										 |  |  | 			}; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-26 04:11:46 +08:00
										 |  |  | 		if ( | 
					
						
							|  |  |  | 			flags[name].configs.some( | 
					
						
							|  |  |  | 				item => JSON.stringify(item) === JSON.stringify(argConfig) | 
					
						
							|  |  |  | 			) | 
					
						
							|  |  |  | 		) { | 
					
						
							|  |  |  | 			return 0; | 
					
						
							| 
									
										
										
										
											2020-03-09 21:18:34 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2020-03-10 20:30:18 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-26 16:48:21 +08:00
										 |  |  | 		if ( | 
					
						
							|  |  |  | 			flags[name].configs.some( | 
					
						
							|  |  |  | 				item => item.type === argConfig.type && item.multiple !== multiple | 
					
						
							|  |  |  | 			) | 
					
						
							|  |  |  | 		) { | 
					
						
							|  |  |  | 			if (multiple) { | 
					
						
							|  |  |  | 				throw new Error( | 
					
						
							|  |  |  | 					`Conflicting schema for ${path[0].path} with ${argConfig.type} type (array type must be before single item type)` | 
					
						
							|  |  |  | 				); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			return 0; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-26 04:11:46 +08:00
										 |  |  | 		flags[name].configs.push(argConfig); | 
					
						
							| 
									
										
										
										
											2020-03-10 20:30:18 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		return 1; | 
					
						
							| 
									
										
										
										
											2020-03-09 23:24:04 +08:00
										 |  |  | 	}; | 
					
						
							| 
									
										
										
										
											2020-03-09 21:18:34 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	// TODO support `not` and `if/then/else`
 | 
					
						
							|  |  |  | 	// TODO support `const`, but we don't use it on our schema
 | 
					
						
							| 
									
										
										
										
											2020-03-09 23:24:04 +08:00
										 |  |  | 	/** | 
					
						
							|  |  |  | 	 * | 
					
						
							|  |  |  | 	 * @param {object} schemaPart the current schema | 
					
						
							|  |  |  | 	 * @param {string} schemaPath the current path in the schema | 
					
						
							| 
									
										
										
										
											2020-03-26 06:27:55 +08:00
										 |  |  | 	 * @param {{schema: object, path: string}[]} path all previous visited schemaParts | 
					
						
							| 
									
										
										
										
											2020-03-09 23:24:04 +08:00
										 |  |  | 	 * @param {string | null} inArray if inside of an array, the path to the array | 
					
						
							| 
									
										
										
										
											2020-03-10 20:30:18 +08:00
										 |  |  | 	 * @returns {number} added arguments | 
					
						
							| 
									
										
										
										
											2020-03-09 23:24:04 +08:00
										 |  |  | 	 */ | 
					
						
							|  |  |  | 	const traverse = (schemaPart, schemaPath = "", path = [], inArray = null) => { | 
					
						
							| 
									
										
										
										
											2020-03-09 21:18:34 +08:00
										 |  |  | 		while (schemaPart.$ref) { | 
					
						
							|  |  |  | 			schemaPart = getSchemaPart(schemaPart.$ref); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-26 06:27:55 +08:00
										 |  |  | 		const repetitions = path.filter(({ schema }) => schema === schemaPart); | 
					
						
							| 
									
										
										
										
											2020-03-09 23:46:31 +08:00
										 |  |  | 		if ( | 
					
						
							| 
									
										
										
										
											2020-03-26 06:27:55 +08:00
										 |  |  | 			repetitions.length >= 2 || | 
					
						
							|  |  |  | 			repetitions.some(({ path }) => path === schemaPath) | 
					
						
							| 
									
										
										
										
											2020-03-09 23:46:31 +08:00
										 |  |  | 		) { | 
					
						
							| 
									
										
										
										
											2020-03-10 20:30:18 +08:00
										 |  |  | 			return 0; | 
					
						
							| 
									
										
										
										
											2020-03-09 23:46:31 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-10 20:30:18 +08:00
										 |  |  | 		if (schemaPart.cli && schemaPart.cli.exclude) return 0; | 
					
						
							| 
									
										
										
										
											2020-03-09 21:18:34 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-09 23:46:31 +08:00
										 |  |  | 		const fullPath = [{ schema: schemaPart, path: schemaPath }, ...path]; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-10 20:30:18 +08:00
										 |  |  | 		let addedArguments = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		addedArguments += addFlag(fullPath, !!inArray); | 
					
						
							| 
									
										
										
										
											2020-03-09 21:18:34 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		if (schemaPart.type === "object") { | 
					
						
							|  |  |  | 			if (schemaPart.properties) { | 
					
						
							| 
									
										
										
										
											2020-03-09 23:24:04 +08:00
										 |  |  | 				for (const property of Object.keys(schemaPart.properties)) { | 
					
						
							| 
									
										
										
										
											2020-03-10 20:30:18 +08:00
										 |  |  | 					addedArguments += traverse( | 
					
						
							| 
									
										
										
										
											2020-03-09 21:18:34 +08:00
										 |  |  | 						schemaPart.properties[property], | 
					
						
							|  |  |  | 						schemaPath ? `${schemaPath}.${property}` : property, | 
					
						
							| 
									
										
										
										
											2020-03-09 23:46:31 +08:00
										 |  |  | 						fullPath, | 
					
						
							| 
									
										
										
										
											2020-03-09 23:24:04 +08:00
										 |  |  | 						inArray | 
					
						
							|  |  |  | 					); | 
					
						
							|  |  |  | 				} | 
					
						
							| 
									
										
										
										
											2020-03-09 21:18:34 +08:00
										 |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-10 20:30:18 +08:00
										 |  |  | 			return addedArguments; | 
					
						
							| 
									
										
										
										
											2020-03-09 21:18:34 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (schemaPart.type === "array") { | 
					
						
							| 
									
										
										
										
											2020-03-09 23:24:04 +08:00
										 |  |  | 			if (inArray) { | 
					
						
							| 
									
										
										
										
											2020-03-10 20:30:18 +08:00
										 |  |  | 				return 0; | 
					
						
							| 
									
										
										
										
											2020-03-09 23:24:04 +08:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2020-03-09 21:18:34 +08:00
										 |  |  | 			if (Array.isArray(schemaPart.items)) { | 
					
						
							| 
									
										
										
										
											2020-03-10 20:30:18 +08:00
										 |  |  | 				let i = 0; | 
					
						
							| 
									
										
										
										
											2020-03-09 23:24:04 +08:00
										 |  |  | 				for (const item of schemaPart.items) { | 
					
						
							| 
									
										
										
										
											2020-03-10 20:30:18 +08:00
										 |  |  | 					addedArguments += traverse( | 
					
						
							|  |  |  | 						item, | 
					
						
							|  |  |  | 						`${schemaPath}.${i}`, | 
					
						
							|  |  |  | 						fullPath, | 
					
						
							|  |  |  | 						schemaPath | 
					
						
							|  |  |  | 					); | 
					
						
							| 
									
										
										
										
											2020-03-09 23:24:04 +08:00
										 |  |  | 				} | 
					
						
							| 
									
										
										
										
											2020-03-09 21:18:34 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-10 20:30:18 +08:00
										 |  |  | 				return addedArguments; | 
					
						
							| 
									
										
										
										
											2020-03-09 21:18:34 +08:00
										 |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-10 20:30:18 +08:00
										 |  |  | 			addedArguments += traverse( | 
					
						
							|  |  |  | 				schemaPart.items, | 
					
						
							| 
									
										
										
										
											2020-03-25 18:36:33 +08:00
										 |  |  | 				`${schemaPath}[]`, | 
					
						
							| 
									
										
										
										
											2020-03-10 20:30:18 +08:00
										 |  |  | 				fullPath, | 
					
						
							|  |  |  | 				schemaPath | 
					
						
							|  |  |  | 			); | 
					
						
							| 
									
										
										
										
											2020-03-09 21:18:34 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-26 06:48:51 +08:00
										 |  |  | 			if (addedArguments > 0) { | 
					
						
							| 
									
										
										
										
											2020-03-10 20:30:18 +08:00
										 |  |  | 				addResetFlag(fullPath); | 
					
						
							|  |  |  | 				addedArguments++; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			return addedArguments; | 
					
						
							| 
									
										
										
										
											2020-03-09 21:18:34 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		const maybeOf = schemaPart.oneOf || schemaPart.anyOf || schemaPart.allOf; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		if (maybeOf) { | 
					
						
							|  |  |  | 			const items = maybeOf; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-09 23:24:04 +08:00
										 |  |  | 			for (let i = 0; i < items.length; i++) { | 
					
						
							| 
									
										
										
										
											2020-03-10 20:30:18 +08:00
										 |  |  | 				addedArguments += traverse(items[i], schemaPath, fullPath, inArray); | 
					
						
							| 
									
										
										
										
											2020-03-09 23:24:04 +08:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2020-03-09 21:18:34 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-10 20:30:18 +08:00
										 |  |  | 			return addedArguments; | 
					
						
							| 
									
										
										
										
											2020-03-09 21:18:34 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2020-03-10 20:30:18 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		return addedArguments; | 
					
						
							| 
									
										
										
										
											2020-03-09 23:24:04 +08:00
										 |  |  | 	}; | 
					
						
							| 
									
										
										
										
											2020-03-09 21:18:34 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	traverse(schema); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-26 04:11:46 +08:00
										 |  |  | 	// Summarize flags
 | 
					
						
							|  |  |  | 	for (const name of Object.keys(flags)) { | 
					
						
							|  |  |  | 		const argument = flags[name]; | 
					
						
							|  |  |  | 		argument.description = argument.configs.reduce((desc, { description }) => { | 
					
						
							|  |  |  | 			if (!desc) return description; | 
					
						
							|  |  |  | 			if (!description) return desc; | 
					
						
							|  |  |  | 			if (desc.includes(description)) return desc; | 
					
						
							|  |  |  | 			return `${desc} ${description}`; | 
					
						
							|  |  |  | 		}, /** @type {string | undefined} */ (undefined)); | 
					
						
							|  |  |  | 		argument.simpleType = argument.configs.reduce((t, argConfig) => { | 
					
						
							|  |  |  | 			/** @type {"string" | "number" | "boolean"} */ | 
					
						
							|  |  |  | 			let type = "string"; | 
					
						
							|  |  |  | 			switch (argConfig.type) { | 
					
						
							|  |  |  | 				case "number": | 
					
						
							|  |  |  | 					type = "number"; | 
					
						
							|  |  |  | 					break; | 
					
						
							| 
									
										
										
										
											2020-03-26 18:37:42 +08:00
										 |  |  | 				case "reset": | 
					
						
							| 
									
										
										
										
											2020-03-26 04:11:46 +08:00
										 |  |  | 				case "boolean": | 
					
						
							|  |  |  | 					type = "boolean"; | 
					
						
							|  |  |  | 					break; | 
					
						
							|  |  |  | 				case "enum": | 
					
						
							|  |  |  | 					if (argConfig.values.every(v => typeof v === "boolean")) | 
					
						
							|  |  |  | 						type = "boolean"; | 
					
						
							|  |  |  | 					if (argConfig.values.every(v => typeof v === "number")) | 
					
						
							|  |  |  | 						type = "number"; | 
					
						
							|  |  |  | 					break; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			if (t === undefined) return type; | 
					
						
							|  |  |  | 			return t === type ? t : "string"; | 
					
						
							|  |  |  | 		}, /** @type {"string" | "number" | "boolean" | undefined} */ (undefined)); | 
					
						
							|  |  |  | 		argument.multiple = argument.configs.some(c => c.multiple); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-09 21:18:34 +08:00
										 |  |  | 	return flags; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-26 04:11:46 +08:00
										 |  |  | const cliAddedItems = new WeakMap(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							|  |  |  |  * @param {any} config configuration | 
					
						
							|  |  |  |  * @param {string} schemaPath path in the config | 
					
						
							|  |  |  |  * @param {number | undefined} index index of value when multiple values are provided, otherwise undefined | 
					
						
							|  |  |  |  * @returns {{ problem?: LocalProblem, object?: any, property?: string | number, value?: any }} problem or object with property and value | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | const getObjectAndProperty = (config, schemaPath, index = 0) => { | 
					
						
							|  |  |  | 	if (!schemaPath) return { value: config }; | 
					
						
							|  |  |  | 	const parts = schemaPath.split("."); | 
					
						
							|  |  |  | 	let property = parts.pop(); | 
					
						
							|  |  |  | 	let current = config; | 
					
						
							|  |  |  | 	let i = 0; | 
					
						
							|  |  |  | 	for (const part of parts) { | 
					
						
							|  |  |  | 		const isArray = part.endsWith("[]"); | 
					
						
							|  |  |  | 		const name = isArray ? part.slice(0, -2) : part; | 
					
						
							|  |  |  | 		let value = current[name]; | 
					
						
							|  |  |  | 		if (isArray) { | 
					
						
							|  |  |  | 			if (value === undefined) { | 
					
						
							|  |  |  | 				value = {}; | 
					
						
							|  |  |  | 				current[name] = [...Array.from({ length: index }), value]; | 
					
						
							|  |  |  | 				cliAddedItems.set(current[name], index + 1); | 
					
						
							|  |  |  | 			} else if (!Array.isArray(value)) { | 
					
						
							|  |  |  | 				return { | 
					
						
							|  |  |  | 					problem: { | 
					
						
							|  |  |  | 						type: "unexpected-non-array-in-path", | 
					
						
							|  |  |  | 						path: parts.slice(0, i).join(".") | 
					
						
							|  |  |  | 					} | 
					
						
							|  |  |  | 				}; | 
					
						
							|  |  |  | 			} else { | 
					
						
							|  |  |  | 				let addedItems = cliAddedItems.get(value) || 0; | 
					
						
							|  |  |  | 				while (addedItems <= index) { | 
					
						
							|  |  |  | 					value.push(undefined); | 
					
						
							|  |  |  | 					addedItems++; | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 				cliAddedItems.set(value, addedItems); | 
					
						
							|  |  |  | 				const x = value.length - addedItems + index; | 
					
						
							|  |  |  | 				if (value[x] === undefined) { | 
					
						
							|  |  |  | 					value[x] = {}; | 
					
						
							|  |  |  | 				} else if (value[x] === null || typeof value[x] !== "object") { | 
					
						
							|  |  |  | 					return { | 
					
						
							|  |  |  | 						problem: { | 
					
						
							|  |  |  | 							type: "unexpected-non-object-in-path", | 
					
						
							|  |  |  | 							path: parts.slice(0, i).join(".") | 
					
						
							|  |  |  | 						} | 
					
						
							|  |  |  | 					}; | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 				value = value[x]; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} else { | 
					
						
							|  |  |  | 			if (value === undefined) { | 
					
						
							|  |  |  | 				value = current[name] = {}; | 
					
						
							|  |  |  | 			} else if (value === null || typeof value !== "object") { | 
					
						
							|  |  |  | 				return { | 
					
						
							|  |  |  | 					problem: { | 
					
						
							|  |  |  | 						type: "unexpected-non-object-in-path", | 
					
						
							|  |  |  | 						path: parts.slice(0, i).join(".") | 
					
						
							|  |  |  | 					} | 
					
						
							|  |  |  | 				}; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		current = value; | 
					
						
							|  |  |  | 		i++; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	let value = current[property]; | 
					
						
							|  |  |  | 	if (property.endsWith("[]")) { | 
					
						
							|  |  |  | 		const name = property.slice(0, -2); | 
					
						
							|  |  |  | 		const value = current[name]; | 
					
						
							|  |  |  | 		if (value === undefined) { | 
					
						
							|  |  |  | 			current[name] = [...Array.from({ length: index }), undefined]; | 
					
						
							|  |  |  | 			cliAddedItems.set(current[name], index + 1); | 
					
						
							|  |  |  | 			return { object: current[name], property: index, value: undefined }; | 
					
						
							|  |  |  | 		} else if (!Array.isArray(value)) { | 
					
						
							|  |  |  | 			current[name] = [value, ...Array.from({ length: index }), undefined]; | 
					
						
							|  |  |  | 			cliAddedItems.set(current[name], index + 1); | 
					
						
							|  |  |  | 			return { object: current[name], property: index + 1, value: undefined }; | 
					
						
							|  |  |  | 		} else { | 
					
						
							|  |  |  | 			let addedItems = cliAddedItems.get(value) || 0; | 
					
						
							|  |  |  | 			while (addedItems <= index) { | 
					
						
							|  |  |  | 				value.push(undefined); | 
					
						
							|  |  |  | 				addedItems++; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			cliAddedItems.set(value, addedItems); | 
					
						
							|  |  |  | 			const x = value.length - addedItems + index; | 
					
						
							|  |  |  | 			if (value[x] === undefined) { | 
					
						
							|  |  |  | 				value[x] = {}; | 
					
						
							|  |  |  | 			} else if (value[x] === null || typeof value[x] !== "object") { | 
					
						
							|  |  |  | 				return { | 
					
						
							|  |  |  | 					problem: { | 
					
						
							|  |  |  | 						type: "unexpected-non-object-in-path", | 
					
						
							|  |  |  | 						path: schemaPath | 
					
						
							|  |  |  | 					} | 
					
						
							|  |  |  | 				}; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			return { | 
					
						
							|  |  |  | 				object: value, | 
					
						
							|  |  |  | 				property: x, | 
					
						
							|  |  |  | 				value: value[x] | 
					
						
							|  |  |  | 			}; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return { object: current, property, value }; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							|  |  |  |  * @param {any} config configuration | 
					
						
							|  |  |  |  * @param {string} schemaPath path in the config | 
					
						
							|  |  |  |  * @param {any} value parsed value | 
					
						
							|  |  |  |  * @param {number | undefined} index index of value when multiple values are provided, otherwise undefined | 
					
						
							|  |  |  |  * @returns {LocalProblem | null} problem or null for success | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | const setValue = (config, schemaPath, value, index) => { | 
					
						
							|  |  |  | 	const { problem, object, property } = getObjectAndProperty( | 
					
						
							|  |  |  | 		config, | 
					
						
							|  |  |  | 		schemaPath, | 
					
						
							|  |  |  | 		index | 
					
						
							|  |  |  | 	); | 
					
						
							|  |  |  | 	if (problem) return problem; | 
					
						
							|  |  |  | 	object[property] = value; | 
					
						
							|  |  |  | 	return null; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							|  |  |  |  * @param {ArgumentConfig} argConfig processing instructions | 
					
						
							|  |  |  |  * @param {any} config configuration | 
					
						
							|  |  |  |  * @param {any} value the value | 
					
						
							|  |  |  |  * @param {number | undefined} index the index if multiple values provided | 
					
						
							|  |  |  |  * @returns {LocalProblem | null} a problem if any | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | const processArgumentConfig = (argConfig, config, value, index) => { | 
					
						
							|  |  |  | 	if (index !== undefined && !argConfig.multiple) { | 
					
						
							|  |  |  | 		return { | 
					
						
							|  |  |  | 			type: "multiple-values-unexpected", | 
					
						
							|  |  |  | 			path: argConfig.path | 
					
						
							|  |  |  | 		}; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	const parsed = parseValueForArgumentConfig(argConfig, value); | 
					
						
							|  |  |  | 	if (parsed === undefined) { | 
					
						
							|  |  |  | 		return { | 
					
						
							|  |  |  | 			type: "invalid-value", | 
					
						
							| 
									
										
										
										
											2020-03-26 23:41:50 +08:00
										 |  |  | 			path: argConfig.path, | 
					
						
							|  |  |  | 			expected: getExpectedValue(argConfig) | 
					
						
							| 
									
										
										
										
											2020-03-26 04:11:46 +08:00
										 |  |  | 		}; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	const problem = setValue(config, argConfig.path, parsed, index); | 
					
						
							|  |  |  | 	if (problem) return problem; | 
					
						
							|  |  |  | 	return null; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-26 23:41:50 +08:00
										 |  |  | /** | 
					
						
							|  |  |  |  * @param {ArgumentConfig} argConfig processing instructions | 
					
						
							|  |  |  |  * @returns {string | undefined} expected message | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | const getExpectedValue = argConfig => { | 
					
						
							|  |  |  | 	switch (argConfig.type) { | 
					
						
							|  |  |  | 		default: | 
					
						
							|  |  |  | 			return argConfig.type; | 
					
						
							|  |  |  | 		case "boolean": | 
					
						
							|  |  |  | 			return "true | false"; | 
					
						
							|  |  |  | 		case "RegExp": | 
					
						
							|  |  |  | 			return "regular expression (example: /ab?c*/)"; | 
					
						
							|  |  |  | 		case "enum": | 
					
						
							|  |  |  | 			return argConfig.values.map(v => `${v}`).join(" | "); | 
					
						
							|  |  |  | 		case "reset": | 
					
						
							|  |  |  | 			return "true (will reset the previous value to an empty array)"; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-26 04:11:46 +08:00
										 |  |  | /** | 
					
						
							|  |  |  |  * @param {ArgumentConfig} argConfig processing instructions | 
					
						
							|  |  |  |  * @param {any} value the value | 
					
						
							|  |  |  |  * @returns {any | undefined} parsed value | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | const parseValueForArgumentConfig = (argConfig, value) => { | 
					
						
							|  |  |  | 	switch (argConfig.type) { | 
					
						
							|  |  |  | 		case "string": | 
					
						
							|  |  |  | 			if (typeof value === "string") { | 
					
						
							|  |  |  | 				return value; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		case "path": | 
					
						
							|  |  |  | 			if (typeof value === "string") { | 
					
						
							|  |  |  | 				return path.resolve(value); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		case "number": | 
					
						
							|  |  |  | 			if (typeof value === "number") return value; | 
					
						
							|  |  |  | 			if (typeof value === "string" && /^[+-]?\d*(\.\d*)[eE]\d+$/) { | 
					
						
							|  |  |  | 				const n = +value; | 
					
						
							| 
									
										
										
										
											2020-07-07 23:18:29 +08:00
										 |  |  | 				if (!isNaN(n)) return n; | 
					
						
							| 
									
										
										
										
											2020-03-26 04:11:46 +08:00
										 |  |  | 			} | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		case "boolean": | 
					
						
							|  |  |  | 			if (typeof value === "boolean") return value; | 
					
						
							|  |  |  | 			if (value === "true") return true; | 
					
						
							|  |  |  | 			if (value === "false") return false; | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		case "RegExp": | 
					
						
							|  |  |  | 			if (value instanceof RegExp) return value; | 
					
						
							|  |  |  | 			if (typeof value === "string") { | 
					
						
							|  |  |  | 				// cspell:word yugi
 | 
					
						
							|  |  |  | 				const match = /^\/(.*)\/([yugi]*)$/.exec(value); | 
					
						
							|  |  |  | 				if (match && !/[^\\]\//.test(match[1])) | 
					
						
							|  |  |  | 					return new RegExp(match[1], match[2]); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		case "enum": | 
					
						
							|  |  |  | 			if (argConfig.values.includes(value)) return value; | 
					
						
							|  |  |  | 			for (const item of argConfig.values) { | 
					
						
							|  |  |  | 				if (`${item}` === value) return item; | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2020-03-26 18:37:42 +08:00
										 |  |  | 			break; | 
					
						
							|  |  |  | 		case "reset": | 
					
						
							|  |  |  | 			if (value === true) return []; | 
					
						
							|  |  |  | 			break; | 
					
						
							| 
									
										
										
										
											2020-03-26 04:11:46 +08:00
										 |  |  | 	} | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-10 20:30:18 +08:00
										 |  |  | /** | 
					
						
							|  |  |  |  * @param {Record<string, Argument>} args object of arguments | 
					
						
							|  |  |  |  * @param {any} config configuration | 
					
						
							| 
									
										
										
										
											2020-03-21 21:01:38 +08:00
										 |  |  |  * @param {Record<string, string | number | boolean | RegExp | (string | number | boolean | RegExp)[]>} values object with values | 
					
						
							| 
									
										
										
										
											2020-03-10 20:30:18 +08:00
										 |  |  |  * @returns {Problem[] | null} problems or null for success | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | const processArguments = (args, config, values) => { | 
					
						
							|  |  |  | 	/** @type {Problem[]} */ | 
					
						
							|  |  |  | 	const problems = []; | 
					
						
							|  |  |  | 	for (const key of Object.keys(values)) { | 
					
						
							|  |  |  | 		const arg = args[key]; | 
					
						
							|  |  |  | 		if (!arg) { | 
					
						
							|  |  |  | 			problems.push({ | 
					
						
							| 
									
										
										
										
											2020-03-26 04:11:46 +08:00
										 |  |  | 				type: "unknown-argument", | 
					
						
							| 
									
										
										
										
											2020-03-10 20:30:18 +08:00
										 |  |  | 				path: "", | 
					
						
							|  |  |  | 				argument: key | 
					
						
							|  |  |  | 			}); | 
					
						
							|  |  |  | 			continue; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2020-03-26 04:11:46 +08:00
										 |  |  | 		const processValue = (value, i) => { | 
					
						
							| 
									
										
										
										
											2020-03-10 20:30:18 +08:00
										 |  |  | 			const currentProblems = []; | 
					
						
							| 
									
										
										
										
											2020-03-26 04:11:46 +08:00
										 |  |  | 			for (const argConfig of arg.configs) { | 
					
						
							|  |  |  | 				const problem = processArgumentConfig(argConfig, config, value, i); | 
					
						
							| 
									
										
										
										
											2020-03-10 20:30:18 +08:00
										 |  |  | 				if (!problem) { | 
					
						
							|  |  |  | 					return; | 
					
						
							|  |  |  | 				} | 
					
						
							| 
									
										
										
										
											2020-03-26 04:11:46 +08:00
										 |  |  | 				currentProblems.push({ | 
					
						
							|  |  |  | 					...problem, | 
					
						
							|  |  |  | 					argument: key, | 
					
						
							|  |  |  | 					value: value, | 
					
						
							|  |  |  | 					index: i | 
					
						
							|  |  |  | 				}); | 
					
						
							| 
									
										
										
										
											2020-03-10 20:30:18 +08:00
										 |  |  | 			} | 
					
						
							|  |  |  | 			problems.push(...currentProblems); | 
					
						
							|  |  |  | 		}; | 
					
						
							|  |  |  | 		let value = values[key]; | 
					
						
							|  |  |  | 		if (Array.isArray(value)) { | 
					
						
							|  |  |  | 			for (let i = 0; i < value.length; i++) { | 
					
						
							| 
									
										
										
										
											2020-03-26 04:11:46 +08:00
										 |  |  | 				processValue(value[i], i); | 
					
						
							| 
									
										
										
										
											2020-03-10 20:30:18 +08:00
										 |  |  | 			} | 
					
						
							|  |  |  | 		} else { | 
					
						
							| 
									
										
										
										
											2020-03-26 04:11:46 +08:00
										 |  |  | 			processValue(value, undefined); | 
					
						
							| 
									
										
										
										
											2020-03-10 20:30:18 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2020-03-25 18:36:33 +08:00
										 |  |  | 	if (problems.length === 0) return null; | 
					
						
							|  |  |  | 	return problems; | 
					
						
							| 
									
										
										
										
											2020-03-10 20:30:18 +08:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-09 23:24:04 +08:00
										 |  |  | exports.getArguments = getArguments; | 
					
						
							| 
									
										
										
										
											2020-03-10 20:30:18 +08:00
										 |  |  | exports.processArguments = processArguments; |