processes() improved command parsing
This commit is contained in:
parent
aa09172366
commit
a11719984f
@ -586,33 +586,42 @@ function processes(callback) {
|
|||||||
if (fullcommand.substr(fullcommand.length - 1) === ']') { fullcommand = fullcommand.slice(0, -1); }
|
if (fullcommand.substr(fullcommand.length - 1) === ']') { fullcommand = fullcommand.slice(0, -1); }
|
||||||
if (fullcommand.substr(0, 1) === '[') { command = fullcommand.substring(1); }
|
if (fullcommand.substr(0, 1) === '[') { command = fullcommand.substring(1); }
|
||||||
else {
|
else {
|
||||||
// try to figure out where parameter starts
|
const p1 = fullcommand.indexOf('(');
|
||||||
let firstParamPos = fullcommand.indexOf(' -');
|
const p2 = fullcommand.indexOf(')');
|
||||||
let firstParamPathPos = fullcommand.indexOf(' /');
|
const p3 = fullcommand.indexOf('/');
|
||||||
firstParamPos = (firstParamPos >= 0 ? firstParamPos : 10000);
|
if (p1 < p2 && p1 < p3 && p3 < p2) {
|
||||||
firstParamPathPos = (firstParamPathPos >= 0 ? firstParamPathPos : 10000);
|
command = fullcommand.split(' ')[0];
|
||||||
const firstPos = Math.min(firstParamPos, firstParamPathPos);
|
command = command.replace(/:/g, '');
|
||||||
let tmpCommand = fullcommand.substr(0, firstPos);
|
} else {
|
||||||
const tmpParams = fullcommand.substr(firstPos);
|
// try to figure out where parameter starts
|
||||||
const lastSlashPos = tmpCommand.lastIndexOf('/');
|
let firstParamPos = fullcommand.indexOf(' -');
|
||||||
if (lastSlashPos >= 0) {
|
let firstParamPathPos = fullcommand.indexOf(' /');
|
||||||
cmdPath = tmpCommand.substr(0, lastSlashPos);
|
firstParamPos = (firstParamPos >= 0 ? firstParamPos : 10000);
|
||||||
tmpCommand = tmpCommand.substr(lastSlashPos + 1);
|
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) {
|
if (firstPos === 10000 && tmpCommand.indexOf(' ') > -1) {
|
||||||
const parts = tmpCommand.split(' ');
|
const parts = tmpCommand.split(' ');
|
||||||
if (fs.existsSync(path.join(cmdPath, parts[0]))) {
|
if (fs.existsSync(path.join(cmdPath, parts[0]))) {
|
||||||
command = parts.shift();
|
command = parts.shift();
|
||||||
params = (parts.join(' ') + ' ' + tmpParams).trim();
|
params = (parts.join(' ') + ' ' + tmpParams).trim();
|
||||||
|
} else {
|
||||||
|
command = tmpCommand.trim();
|
||||||
|
params = tmpParams.trim();
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
command = tmpCommand.trim();
|
command = tmpCommand.trim();
|
||||||
params = tmpParams.trim();
|
params = tmpParams.trim();
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
command = tmpCommand.trim();
|
|
||||||
params = tmpParams.trim();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return ({
|
return ({
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user