diff --git a/utils/parseCommand.js b/utils/parseCommand.js index e001db0..8478609 100644 --- a/utils/parseCommand.js +++ b/utils/parseCommand.js @@ -1,17 +1,21 @@ -module.exports = (input) => { +module.exports = (input, allowed) => { 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("--") && !curr) { + if (a.startsWith("--") && !curr && isAllowed(a.slice(2).split("=")[0], allowed)) { 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; + if (!value.endsWith("\"")) { + args[arg] = value.slice(1).slice(0, -1); + } else { + args[arg] = `${value.slice(1)} `; + ended = false; + } } else if (value.endsWith("\"")) { args[arg] += a.slice(0, -1); } else if (value !== "") { @@ -56,6 +60,11 @@ module.exports = (input) => { return args; }; +const isAllowed = (input, allowed) => { + if (!allowed) return true; + return allowed.includes(input); +}; + // /* // Format: // [{name: "verbose", type: "bool"}, {name: "username", type: "string"}]