Skip to content

Commit d9cf4e0

Browse files
Copilotfbosch
andauthored
Add --silent flag to suppress non-error output (#12)
* Initial plan * Add --silent flag to suppress non-error output Co-authored-by: fbosch <6979916+fbosch@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: fbosch <6979916+fbosch@users.noreply.github.com>
1 parent 0eb7753 commit d9cf4e0

5 files changed

Lines changed: 45 additions & 2 deletions

File tree

src/cli/index.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import pc from "picocolors";
44
import { ExitCode } from "./exit-code";
55
import { parseArgs } from "./parse-args";
66
import type { CliOptions } from "./types";
7-
import { symbols, ui } from "./ui";
7+
import { setSilentMode, symbols, ui } from "./ui";
88

99
export const CLI_NAME = "docs-cache";
1010

@@ -33,6 +33,7 @@ Global options:
3333
--concurrency <n>
3434
--json
3535
--timeout-ms <n>
36+
--silent
3637
`;
3738

3839
const printHelp = () => {
@@ -324,6 +325,9 @@ export async function main(): Promise<void> {
324325
const parsed = parseArgs();
325326
const _rawArgs = parsed.rawArgs;
326327

328+
// Set silent mode if the flag is present
329+
setSilentMode(parsed.options.silent);
330+
327331
if (parsed.help) {
328332
printHelp();
329333
process.exit(ExitCode.Success);

src/cli/parse-args.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ export const parseArgs = (argv = process.argv): ParsedArgs => {
4141
.option("--concurrency <n>", "Concurrency limit")
4242
.option("--json", "Output JSON")
4343
.option("--timeout-ms <n>", "Network timeout in milliseconds")
44+
.option("--silent", "Suppress non-error output")
4445
.help();
4546

4647
const result = cli.parse(argv, { run: false });
@@ -64,6 +65,7 @@ export const parseArgs = (argv = process.argv): ParsedArgs => {
6465
timeoutMs: result.options.timeoutMs
6566
? Number(result.options.timeoutMs)
6667
: undefined,
68+
silent: Boolean(result.options.silent),
6769
};
6870

6971
if (options.concurrency !== undefined && options.concurrency < 1) {

src/cli/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@ export type CliOptions = {
99
concurrency?: number;
1010
json: boolean;
1111
timeoutMs?: number;
12+
silent: boolean;
1213
};

src/cli/ui.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@ export const symbols = {
99
warn: pc.yellow("⚠"),
1010
};
1111

12+
let _silentMode = false;
13+
14+
export const setSilentMode = (silent: boolean) => {
15+
_silentMode = silent;
16+
};
17+
1218
export const ui = {
1319
// Formatters
1420
path: (value: string) => {
@@ -24,19 +30,25 @@ export const ui = {
2430
pad: (value: string, length: number) => value.padEnd(length),
2531

2632
// Components
27-
line: (text: string = "") => process.stdout.write(`${text}\n`),
33+
line: (text: string = "") => {
34+
if (_silentMode) return;
35+
process.stdout.write(`${text}\n`);
36+
},
2837

2938
header: (label: string, value: string) => {
39+
if (_silentMode) return;
3040
process.stdout.write(`${pc.blue("ℹ")} ${label.padEnd(10)} ${value}\n`);
3141
},
3242

3343
item: (icon: string, label: string, details?: string) => {
44+
if (_silentMode) return;
3445
const partLabel = pc.bold(label);
3546
const partDetails = details ? pc.gray(details) : "";
3647
process.stdout.write(` ${icon} ${partLabel} ${partDetails}\n`);
3748
},
3849

3950
step: (action: string, subject: string, details?: string) => {
51+
if (_silentMode) return;
4052
const icon = pc.cyan("→");
4153
process.stdout.write(
4254
` ${icon} ${action} ${pc.bold(subject)}${details ? ` ${pc.dim(details)}` : ""}\n`,

tests/cli-parse.test.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,3 +104,27 @@ test("parseArgs handles ssh repo only", async (t) => {
104104
"git@github.com:fbosch/docs-cache.git",
105105
]);
106106
});
107+
108+
test("parseArgs handles --silent flag", async (t) => {
109+
const module = await loadCliModule();
110+
if (!module) {
111+
t.skip("CLI not built yet");
112+
return;
113+
}
114+
const result = module.parseArgs(["node", "docs-cache", "status", "--silent"]);
115+
116+
assert.equal(result.command, "status");
117+
assert.equal(result.options.silent, true);
118+
});
119+
120+
test("parseArgs silent flag defaults to false", async (t) => {
121+
const module = await loadCliModule();
122+
if (!module) {
123+
t.skip("CLI not built yet");
124+
return;
125+
}
126+
const result = module.parseArgs(["node", "docs-cache", "status"]);
127+
128+
assert.equal(result.command, "status");
129+
assert.equal(result.options.silent, false);
130+
});

0 commit comments

Comments
 (0)