Lint command parser

This commit is contained in:
TheEssem 2021-05-17 16:49:21 -05:00
parent b748e54437
commit c92b9a7b25
No known key found for this signature in database
GPG key ID: A3F9F02129092FCA

View file

@ -1,42 +1,40 @@
module.exports = (input) => {
input = input.split(" ");
let args = {_: []};
let curr = null;
let cont = false;
for (let i = 0; i < input.length; i++) {
const a = input[i];
if(a.startsWith('--')) {
if(curr) {
args[curr] = true;
}
args[a.slice(2)] = "";
curr = a.slice(2);
} else if(curr) {
if(a.startsWith('"')) {
args[curr] = a.slice(1)+" ";
} else if(a.endsWith('"')) {
args[curr] += a.slice(0, -1);
curr = null;
} else {
if(args[curr].split(" ").length == 1) {
args[curr] += a;
curr = null;
} else {
args[curr] += a;
}
}
} else {
args._.push(a);
}
}
if(curr && args[curr] == "") {
input = input.split(" ");
const args = { _: [] };
let curr = null;
for (let i = 0; i < input.length; i++) {
const a = input[i];
if (a.startsWith("--")) {
if (curr) {
args[curr] = true;
}
args[a.slice(2)] = "";
curr = a.slice(2);
} else if (curr) {
if (a.startsWith("\"")) {
args[curr] = `${a.slice(1)} `;
} else if (a.endsWith("\"")) {
args[curr] += a.slice(0, -1);
curr = null;
} else {
if (args[curr].split(" ").length == 1) {
args[curr] += a;
curr = null;
} else {
args[curr] += a;
}
}
} else {
args._.push(a);
}
}
return args;
}
if (curr && args[curr] == "") {
args[curr] = true;
}
return args;
};
// /*
// Format: