From c92b9a7b2579be7503a9b043eca8f6e72226f934 Mon Sep 17 00:00:00 2001 From: TheEssem Date: Mon, 17 May 2021 16:49:21 -0500 Subject: [PATCH] Lint command parser --- utils/parseCommand.js | 68 +++++++++++++++++++++---------------------- 1 file changed, 33 insertions(+), 35 deletions(-) diff --git a/utils/parseCommand.js b/utils/parseCommand.js index 06119cf..7c228cf 100644 --- a/utils/parseCommand.js +++ b/utils/parseCommand.js @@ -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: