commandDispatcher: argv only parsed if front of arguments

This commit is contained in:
Cynthia Foxwell 2023-04-26 16:45:27 -06:00
parent 2851dbed24
commit a9c293e8fb

View file

@ -21,11 +21,11 @@ function removeStartHyphens(val) {
// taken from ethanent/gar // taken from ethanent/gar
// modified to make - arguments only be bools unless = // modified to make - arguments only be bools unless =
function parseAsArgv(argv) { function parseAsArgv(args) {
const optional = {}; const optional = {};
const args = [];
for (const arg of argv) { for (let i = 0; i < args.length; i++) {
const arg = args.shift();
const equalsIndex = arg.charAt(0) === "-" ? arg.indexOf("=") : -1; const equalsIndex = arg.charAt(0) === "-" ? arg.indexOf("=") : -1;
const argName = const argName =
equalsIndex === -1 equalsIndex === -1
@ -43,7 +43,9 @@ function parseAsArgv(argv) {
} }
} }
} else { } else {
args.push(convertIfApplicable(argName)); // all optional args must be at the start of the argument string
args.splice(0, 0, arg);
break;
} }
} }