UNPKG

@vigilbase/cli

Version:

Vigilbase CLI — security scanners, agent tools, and Vigilbase One from the terminal.

48 lines (47 loc) • 1.83 kB
import { printJson as writeJson } from '../lib/format.js'; import { withProgress } from '../lib/progress.js'; import { EXIT } from '../types.js'; import { getOneAccessToken } from '../auth/index.js'; import { VigilbaseOneClient as OneClient } from '../lib/one-client.js'; /** Reject known flags from other command groups instead of silently ignoring filters. */ export function assertCommandFlags(ctx, allowed) { const common = new Set(['isJson', 'isHelp', 'isVersion', 'base-url', 'one-url', 'auth-url', 'client-id', 'timeout']); for (const [key, value] of Object.entries(ctx.values)) { if (value === undefined || value === false || common.has(key) || allowed.includes(key)) continue; const flag = key.startsWith('is') ? key.slice(2).replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase() : key; throw new Error(`--${flag} is not supported for this ${ctx.command} command.`); } } export function outputJson(ctx, value) { writeJson(ctx.writer, value); } export function outputLines(ctx, lines) { for (const line of lines) { ctx.writer.stdout(line); } } export function asRecord(value) { if (!value || typeof value !== 'object' || Array.isArray(value)) return null; return value; } export function asArray(value) { return Array.isArray(value) ? value : []; } export async function requireOneClient(ctx) { const accessToken = await getOneAccessToken(ctx.config); if (!accessToken) { throw new Error('This command requires Vigilbase One auth. Run `vigilbase login` first.'); } return new OneClient(ctx.config, accessToken, true); } export async function withSpinner(ctx, label, work) { return withProgress(label, ctx.mode, work); } export function ok() { return EXIT.OK; } export { EXIT };