Something went wrong. Try again.
Something went wrong. Try again.
689 B · 27 lines
TypeScript
at main
12345678910111213141516171819202122232425262728import { Command } from "commander";
export interface GlobalOpts { json?: boolean;}
/** * Read --json from the command's or any ancestor's parsed options. Commander * doesn't walk up the chain by default, so we do it ourselves. */export function globalOpts(cmd: Command): GlobalOpts { let c: Command | null = cmd; while (c) { const o = c.opts() as GlobalOpts; if (o.json !== undefined) return { json: o.json }; c = c.parent; } return {};}
export function jsonOut(value: unknown): void { process.stdout.write(JSON.stringify(value) + "\n");}
export function textOut(line: string): void { process.stdout.write(line.endsWith("\n") ? line : line + "\n");}