Spaces:
Sleeping
Sleeping
File size: 636 Bytes
a5d1c1b | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | export interface OutputOptions {
json?: boolean;
}
export function outputResult<T>(
data: T,
options: OutputOptions,
renderHuman: () => void
): void {
if (options.json) {
console.log(JSON.stringify(data, null, 2));
} else {
renderHuman();
}
}
export function outputError(
error: string,
code: string,
options: OutputOptions,
statusCode = 1
): never {
if (options.json) {
console.error(
JSON.stringify(
{
error,
code,
},
null,
2
)
);
} else {
console.error(`✖ Error [${code}]: ${error}`);
}
process.exit(statusCode);
}
|