Files
knowledge-one-view-cli/scripts/lib/cli-shared.mjs

31 lines
805 B
JavaScript

export function parseArgs(argv) {
const args = {};
for (let index = 0; index < argv.length; index += 1) {
const token = argv[index];
if (!token.startsWith("--")) continue;
const key = token.slice(2);
const next = argv[index + 1];
if (!next || next.startsWith("--")) {
args[key] = "true";
continue;
}
const valueParts = [next];
let valueIndex = index + 2;
while (valueIndex < argv.length && !argv[valueIndex].startsWith("--")) {
valueParts.push(argv[valueIndex]);
valueIndex += 1;
}
args[key] = valueParts.join(" ");
index = valueIndex - 1;
}
return args;
}
export function splitCsv(value, fallback = []) {
if (!value) return fallback;
return value
.split(",")
.map((item) => item.trim())
.filter(Boolean);
}