sda
Version:
Software development assistant
37 lines • 1.24 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
function processCommandParams(command, params) {
const cmds = command.cmd;
const paramString = params ? getParamString(command, params) : '';
for (let i = 0; i < cmds.length; i++) {
cmds[i] = addParams(cmds[i], paramString);
}
return command;
}
exports.default = processCommandParams;
/**
* Finds all valid params for the specified command and concatenates them as a string.
*/
function getParamString(command, params) {
if (!command.validParams || command.validParams.length === 0) {
return '';
}
let paramString = '';
for (const param of params) {
if (command.validParams.indexOf(param[0]) > -1) {
paramString += ' ' + param.join(' ');
}
}
return paramString.trim();
}
/**
* Adds parameter string to the command
* If placeholder exists, add param string there. Otherwise, add to end.
*/
function addParams(cmd, paramString) {
if (cmd.indexOf('%PARAM%') > -1) {
return cmd.replace('%PARAM%', paramString);
}
return !!paramString ? cmd + ' ' + paramString : cmd;
}
//# sourceMappingURL=processCommandParams.js.map