import type { Envelope } from "@/interfaces"; import { nowMs } from "@/utils/dates"; export const ExitCodes = { OK: 0, USAGE: 2, NETWORK: 3, PARTIAL: 4 } as const; export type ExitCode = (typeof ExitCodes)[keyof typeof ExitCodes]; export const wrap = (command: string, data: T, warnings: string[] = []): Envelope => ({ ok: true, command, generatedAt: nowMs(), data, warnings }); export const wrapError = (command: string, data: T, warnings: string[] = []): Envelope => ({ ok: false, command, generatedAt: nowMs(), data, warnings }); export function exitWith(code: ExitCode, message?: string): never { if (message) process.stderr.write(`${message}\n`); process.exit(code); }