mirror of
https://github.com/vrtmrz/obsidian-livesync.git
synced 2026-10-24 10:03:20 +00:00
refactor: inject CLI I/O and diagnostics
This commit is contained in:
1 parent
1b4a0d76dd
commit
97964fddf1
23 files changed
+422
-236
No files matched your search
@@ -0,0 +1,30 @@
|
||||
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));
|
||||
}
|
||||
Reference in new issue
Block a user