From a11719984fa93ae54ab3524bc8c6e25402c5ff08 Mon Sep 17 00:00:00 2001 From: Sebastian Hildebrandt Date: Fri, 24 Jun 2022 18:55:56 +0200 Subject: [PATCH] processes() improved command parsing --- lib/processes.js | 51 ++++++++++++++++++++++++++++-------------------- 1 file changed, 30 insertions(+), 21 deletions(-) diff --git a/lib/processes.js b/lib/processes.js index 79af85d..f1cb08e 100644 --- a/lib/processes.js +++ b/lib/processes.js @@ -586,33 +586,42 @@ function processes(callback) { if (fullcommand.substr(fullcommand.length - 1) === ']') { fullcommand = fullcommand.slice(0, -1); } if (fullcommand.substr(0, 1) === '[') { command = fullcommand.substring(1); } else { - // try to figure out where parameter starts - let firstParamPos = fullcommand.indexOf(' -'); - let firstParamPathPos = fullcommand.indexOf(' /'); - firstParamPos = (firstParamPos >= 0 ? firstParamPos : 10000); - firstParamPathPos = (firstParamPathPos >= 0 ? firstParamPathPos : 10000); - const firstPos = Math.min(firstParamPos, firstParamPathPos); - let tmpCommand = fullcommand.substr(0, firstPos); - const tmpParams = fullcommand.substr(firstPos); - const lastSlashPos = tmpCommand.lastIndexOf('/'); - if (lastSlashPos >= 0) { - cmdPath = tmpCommand.substr(0, lastSlashPos); - tmpCommand = tmpCommand.substr(lastSlashPos + 1); - } + const p1 = fullcommand.indexOf('('); + const p2 = fullcommand.indexOf(')'); + const p3 = fullcommand.indexOf('/'); + if (p1 < p2 && p1 < p3 && p3 < p2) { + command = fullcommand.split(' ')[0]; + command = command.replace(/:/g, ''); + } else { + // try to figure out where parameter starts + let firstParamPos = fullcommand.indexOf(' -'); + let firstParamPathPos = fullcommand.indexOf(' /'); + firstParamPos = (firstParamPos >= 0 ? firstParamPos : 10000); + firstParamPathPos = (firstParamPathPos >= 0 ? firstParamPathPos : 10000); + const firstPos = Math.min(firstParamPos, firstParamPathPos); + let tmpCommand = fullcommand.substr(0, firstPos); + const tmpParams = fullcommand.substr(firstPos); + const lastSlashPos = tmpCommand.lastIndexOf('/'); + if (lastSlashPos >= 0) { + cmdPath = tmpCommand.substr(0, lastSlashPos); + tmpCommand = tmpCommand.substr(lastSlashPos + 1); + } - if (firstPos === 10000 && tmpCommand.indexOf(' ') > -1) { - const parts = tmpCommand.split(' '); - if (fs.existsSync(path.join(cmdPath, parts[0]))) { - command = parts.shift(); - params = (parts.join(' ') + ' ' + tmpParams).trim(); + if (firstPos === 10000 && tmpCommand.indexOf(' ') > -1) { + const parts = tmpCommand.split(' '); + if (fs.existsSync(path.join(cmdPath, parts[0]))) { + command = parts.shift(); + params = (parts.join(' ') + ' ' + tmpParams).trim(); + } else { + command = tmpCommand.trim(); + params = tmpParams.trim(); + } } else { command = tmpCommand.trim(); params = tmpParams.trim(); } - } else { - command = tmpCommand.trim(); - params = tmpParams.trim(); } + } return ({