@vigilbase/cli
Version:
Vigilbase CLI — security scanners, agent tools, and Vigilbase One from the terminal.
33 lines (32 loc) • 1.79 kB
JavaScript
import { z } from 'zod';
import { assertCommandFlags } from './helpers.js';
/**
* Exactly `count` positional arguments. When some are missing, they are named from the trailing `<placeholders>`
* of `usage` (for example `vigilbase run <tool> <target>`), so `usage` lists only positional placeholders.
*/
export function validateArguments(ctx, count, flags = [], usage) {
if (ctx.rest.length < count)
throw new Error(missingArguments(ctx.command, count - ctx.rest.length, usage));
if (ctx.rest.length > count)
throw new Error(`Unexpected arguments. Run \`vigilbase ${ctx.command} --help\` for usage.`);
assertCommandFlags(ctx, flags);
}
/** "Missing <target>. Usage: vigilbase headers <url>", or a pointer to --help without a usage. */
export function missingArguments(command, missingCount, usage) {
const missing = usage?.match(/<[^>]+>/g)?.slice(-missingCount) ?? [];
if (!usage || missing.length !== missingCount)
return `Missing arguments. Run \`vigilbase ${command} --help\` for usage.`;
return `Missing ${missing.join(' and ')}. Usage: ${usage}`;
}
export function limitValue(raw, fallback, max) {
if (raw === undefined)
return fallback;
if (!/^\d+$/.test(raw))
throw new Error('--limit must be an integer.');
return z.number().int().min(1).max(max).parse(Number(raw));
}
export const invitationSchema = z.object({
email: z.string().trim().email(),
role: z.enum(['admin', 'member', 'readonly', 'partner_owner', 'partner_sales', 'partner_operations', 'partner_finance', 'partner_readonly', 'billing_only', 'sales_only']).default('member'),
});
export const toolNameSchema = z.string().trim().min(1).max(128).regex(/^[a-z0-9-]+$/, 'Tool names must contain lowercase letters, digits, or hyphens.');