-
Notifications
You must be signed in to change notification settings - Fork 42
Expand file tree
/
Copy pathno-log.mts
More file actions
34 lines (30 loc) · 1022 Bytes
/
no-log.mts
File metadata and controls
34 lines (30 loc) · 1022 Bytes
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
/**
* Module-level "no-log" mode used to keep stdout clean for automation.
*
* When enabled (via `--no-log`, or implicitly by `--json` / `--markdown`),
* informational CLI output routes to stderr instead of stdout. The primary
* result payload (JSON, Markdown, or plain-text report) is still the only
* thing that appears on stdout, so consumers can pipe it safely.
*/
let noLogMode = false
export function setNoLogMode(on: boolean): void {
noLogMode = on
}
export function isNoLogMode(): boolean {
return noLogMode
}
/**
* Returns true when the caller should route informational output to
* stderr instead of stdout — either because `--no-log` was passed, or
* because the user asked for a machine-readable output format that
* must not be polluted by human-readable log lines.
*/
export function shouldQuietStdout(flags?: Record<string, unknown>): boolean {
if (noLogMode) {
return true
}
if (!flags) {
return false
}
return Boolean(flags['json']) || Boolean(flags['markdown'])
}