src/app/command-processor.js
function parseParams(yargs, argv, path, params) {
	let required = 0;
	let optional = 0;
	let variadic = false;

	argv.params = {};

	const extra = argv._.slice(path.length);

	argv._ = argv._.slice(0, path.length);

	params.replace(/(<[^>]+>|\[[^\]]+\])/g,
		(match) => {
			if (variadic) {
				throw variadicParameterPositionError(variadic);
			}

			const isRequired = match[0] === '<';
			const param = match
				.slice(1, -1)
				.replace(/(.*)\.\.\.$/, (m, param) => {
					variadic = true;
					return param;
				});
			let value;
			if (isRequired) {
				required++;
			} else {
				optional++;
			}

			if (variadic) {
				variadic = param; // save the name
				value = extra.slice(-1 + required + optional).map(String);

				if (isRequired && !value.length) {
					throw variadicParameterRequiredError(param);
				}
			} else {
				if (isRequired && optional > 0) {
					throw requiredParameterPositionError(param);
				}

				value = extra[-1 + required + optional];

				if (value) {
					value = String(value);
				}

				if (isRequired && typeof value === 'undefined') {
					throw requiredParameterError(param);
				}
			}

			const params = param.split('|');
			params.forEach(p => {
				argv.params[p] = value;
			});
		});

	if (!variadic && required+optional < extra.length) {
		throw unknownParametersError(extra.slice(required+optional));
	}
}
function parseParams(yargs, argv, path, params) {
	let required = 0;
	let optional = 0;
	let variadic = false;

	argv.params = {};

	const extra = argv._.slice(path.length);

	argv._ = argv._.slice(0, path.length);

	params.replace(/(<[^>]+>|\[[^\]]+\])/g,
		(match) => {
			if (variadic) {
				throw variadicParameterPositionError(variadic);
			}

			const isRequired = match[0] === '<';
			const param = match
				.slice(1, -1)
				.replace(/(.*)\.\.\.$/, (m, param) => {
					variadic = true;
					return param;
				});
			let value;
			if (isRequired) {
				required++;
			} else {
				optional++;
			}

			if (variadic) {
				variadic = param; // save the name
				value = extra.slice(-1 + required + optional).map(String);

				if (isRequired && !value.length) {
					throw variadicParameterRequiredError(param);
				}
			} else {
				if (isRequired && optional > 0) {
					throw requiredParameterPositionError(param);
				}

				value = extra[-1 + required + optional];

				if (value) {
					value = String(value);
				}

				if (isRequired && typeof value === 'undefined') {
					throw requiredParameterError(param);
				}
			}

			const params = param.split('|');
			params.forEach(p => {
				argv.params[p] = value;
			});
		});

	if (!variadic && required+optional < extra.length) {
		throw unknownParametersError(extra.slice(required+optional));
	}
}
function parseParams ( yargs , argv , path , params ) { let required = 0 ; let optional = 0 ; let variadic = false ; argv . params = { } ; const extra = argv . _ . slice ( path . length ) ; argv . _ = argv . _ . slice ( 0 , path . length ) ; params . replace ( / (<[^>]+>|\[[^\]]+\]) / g , ( match ) => { if ( variadic ) { throw variadicParameterPositionError ( variadic ) ; } const isRequired = match [ 0 ] === '<' ; const param = match . slice ( 1 , - 1 ) . replace ( / (.*)\.\.\.$ / , ( m , param ) => { variadic = true ; return param ; } ) ; let value ; if ( isRequired ) { required ++ ; } else { optional ++ ; } if ( variadic ) { variadic = param ; // save the name value = extra . slice ( - 1 + required + optional ) . map ( String ) ; if ( isRequired && ! value . length ) { throw variadicParameterRequiredError ( param ) ; } } else { if ( isRequired && optional > 0 ) { throw requiredParameterPositionError ( param ) ; } value = extra [ - 1 + required + optional ] ; if ( value ) { value = String ( value ) ; } if ( isRequired && typeof value === 'undefined' ) { throw requiredParameterError ( param ) ; } } const params = param . split ( '|' ) ; params . forEach ( p => { argv . params [ p ] = value ; } ) ; } ) ; if ( ! variadic && required + optional < extra . length ) { throw unknownParametersError ( extra . slice ( required + optional ) ) ; } }
Parses parameters specified with the given command. The parsed params are stored as
`argv.params`.
@param {object} yargs    The yargs command line parser
@param {Array<String>} argv     The parsed command line
@param {Array<String>} path     The command path the params apply to
@param {string} params   The params to parse.
Parses parameters specified with the given command . The parsed params are stored as argv . params .