Replace /phonestatus follow-ups with /voicestatus, /wanstatus, /phonediag, and /dectdiag; extend /voicediag with relay probes and section-based MPP diagnostics. Co-authored-by: Cursor <cursoragent@cursor.com>
37 lines
1.3 KiB
JavaScript
37 lines
1.3 KiB
JavaScript
// utils/windowArgs.js
|
|
//
|
|
// Shared `--window` parsing for /wanstatus and /voicediag.
|
|
|
|
export function pickWindowArg(args) {
|
|
return pickFlagValue(args, '--window');
|
|
}
|
|
|
|
function pickFlagValue(args, flag) {
|
|
const prefix = `${flag.toLowerCase()}=`;
|
|
for (let i = 0; i < args.length; i += 1) {
|
|
const a = String(args[i] || '').toLowerCase();
|
|
if (a.startsWith(prefix)) return String(args[i]).slice(prefix.length);
|
|
if (a === flag.toLowerCase() && i + 1 < args.length) return args[i + 1];
|
|
}
|
|
return null;
|
|
}
|
|
|
|
/**
|
|
* Parse a window shorthand (`15m`, `1h`, `24h`, `1d`, `1440`) into
|
|
* minutes. Returns null on unrecognised input so the caller can
|
|
* decide whether to surface a friendly error or fall back to the
|
|
* env default.
|
|
*/
|
|
export function parseWindowMinutes(raw) {
|
|
if (raw === null || raw === undefined || raw === '') return undefined;
|
|
const s = String(raw).trim().toLowerCase();
|
|
if (/^\d+$/.test(s)) return Math.max(1, parseInt(s, 10));
|
|
const m = s.match(/^(\d+)\s*(m|min|mins|h|hr|hrs|hour|hours|d|day|days)$/);
|
|
if (!m) return null;
|
|
const n = parseInt(m[1], 10);
|
|
const unit = m[2];
|
|
if (['m', 'min', 'mins'].includes(unit)) return n;
|
|
if (['h', 'hr', 'hrs', 'hour', 'hours'].includes(unit)) return n * 60;
|
|
if (['d', 'day', 'days'].includes(unit)) return n * 60 * 24;
|
|
return null;
|
|
}
|