From 8b07524e6b73d2bcbb55698653a53262686e41c4 Mon Sep 17 00:00:00 2001 From: TheEssem Date: Sat, 5 Jun 2021 19:55:40 -0500 Subject: [PATCH] Command parser changes --- utils/parseCommand.js | 50 ++++++++++++++++++++++++++++++------------- 1 file changed, 35 insertions(+), 15 deletions(-) diff --git a/utils/parseCommand.js b/utils/parseCommand.js index 7c228cf..e001db0 100644 --- a/utils/parseCommand.js +++ b/utils/parseCommand.js @@ -2,30 +2,50 @@ module.exports = (input) => { input = input.split(" "); const args = { _: [] }; let curr = null; + let concated = ""; for (let i = 0; i < input.length; i++) { const a = input[i]; - if (a.startsWith("--")) { - if (curr) { - args[curr] = true; + if (a.startsWith("--") && !curr) { + if (a.includes("=")) { + const [ arg, value ] = a.slice(2).split("="); + let ended = true; + if (value.startsWith("\"")) { + args[arg] = `${value.slice(1)} `; + if (!value.endsWith("\"")) ended = false; + } else if (value.endsWith("\"")) { + args[arg] += a.slice(0, -1); + } else if (value !== "") { + args[arg] = value; + } else { + args[arg] = true; + } + if (!ended) curr = arg; + } else { + args[a.slice(2)] = true; } - args[a.slice(2)] = ""; - curr = a.slice(2); } else if (curr) { - if (a.startsWith("\"")) { - args[curr] = `${a.slice(1)} `; - } else if (a.endsWith("\"")) { + 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; - } + args[curr] += `${a} `; } + } else if (a.startsWith("\"")) { + if (a.endsWith("\"")) { + args.push(a.slice(1).slice(0, -1)); + } else { + concated += `${a.slice(1)} `; + } + } else if (a.endsWith("\"")) { + concated += a.slice(0, -1); + args._.push(concated); + concated = ""; } else { - args._.push(a); + if (concated !== "") { + concated += `${a} `; + } else { + args._.push(a); + } } }