mirror of
https://github.com/vrtmrz/obsidian-livesync.git
synced 2026-07-30 16:33:01 +00:00
31 lines
1.1 KiB
TypeScript
31 lines
1.1 KiB
TypeScript
import type { StandardIo } from "@vrtmrz/livesync-commonlib/context";
|
|
|
|
/** Report a CLI-owned diagnostic without selecting its final presentation channel. */
|
|
export type CliDiagnosticReporter = (message: string, detail?: unknown) => void;
|
|
|
|
function formatValue(value: unknown): string {
|
|
if (typeof value === "string") return value;
|
|
if (value instanceof Error) return value.stack ?? value.message;
|
|
try {
|
|
const encoded = JSON.stringify(value);
|
|
if (encoded !== undefined) return encoded;
|
|
} catch {
|
|
// Fall through to the host-independent string conversion.
|
|
}
|
|
return String(value);
|
|
}
|
|
|
|
function formatLine(values: readonly unknown[]): string {
|
|
return `${values.map(formatValue).join(" ")}\n`;
|
|
}
|
|
|
|
/** Render one user-facing line on standard output. */
|
|
export function writeStdoutLine(standardIo: StandardIo, ...values: readonly unknown[]): void {
|
|
standardIo.writeStdout(formatLine(values));
|
|
}
|
|
|
|
/** Render one user-facing or diagnostic line on standard error. */
|
|
export function writeStderrLine(standardIo: StandardIo, ...values: readonly unknown[]): void {
|
|
standardIo.writeStderr(formatLine(values));
|
|
}
|