← back to Interiordesignershowroom
lib/run-guard.js
26 lines
// Shared CLI guards for the paid backfill drivers (TK-10402).
// Keeps --dry-run / --limit / --max-cost parsing identical across
// scripts/backfill-room-scenes.js and scripts/gen-guide-heroes.js so a cap set on one
// behaves the same on the other.
const argv = process.argv;
// Number of consecutive provider failures after which a batch aborts. An unfunded or
// revoked credential fails identically every call, so without this a batch burns the
// whole target list emitting the same error hundreds of times.
const MAX_FAILS = Number(process.env.MAX_CONSECUTIVE_FAILS || 3);
function flag(name) { return argv.includes(name); }
function num(name, fallback) {
const i = argv.indexOf(name);
if (i === -1) return fallback;
const v = Number(argv[i + 1]);
if (!Number.isFinite(v)) {
console.error(`[run-guard] ${name} needs a number (got "${argv[i + 1]}")`);
process.exit(2);
}
return v;
}
module.exports = { flag, num, MAX_FAILS };