Skip to content

Commit 940acc9

Browse files
Copilotfuxingloh
andcommitted
chore: use shared output resolver
Co-authored-by: fuxingloh <4266087+fuxingloh@users.noreply.github.com>
1 parent 90fbde9 commit 940acc9

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

packages/use-agently/src/bin.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,17 @@ import { cli } from "./cli";
44
import { checkAutoUpdate } from "./commands/update.js";
55
import { installTelemetry, flushTelemetry } from "./telemetry.js";
66
import { handleCliError } from "./errors.js";
7+
import { getOutputFormat } from "./output.js";
78

89
installTelemetry(cli);
910

1011
function resolveOutputFormat(): "tui" | "json" {
11-
const opts = cli.optsWithGlobals?.();
12-
if (opts?.output === "tui" || opts?.output === "json") return opts.output;
12+
try {
13+
return getOutputFormat(cli);
14+
} catch {
15+
// Fallback for unexpected failures before Commander parses options.
16+
return process.stderr.isTTY ? "tui" : "json";
17+
}
1318
return process.stderr.isTTY ? "tui" : "json";
1419
}
1520

packages/use-agently/src/errors.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ describe("handleCliError", () => {
99
beforeEach(() => {
1010
originalIsTTY = process.stderr.isTTY;
1111
exitSpy = spyOn(process, "exit").mockImplementation((code?: number) => {
12-
throw new Error(`exit:${code}`);
12+
throw new Error(`exit:${code ?? 0}`);
1313
});
1414
errorSpy = spyOn(console, "error").mockImplementation(() => {});
1515
});

0 commit comments

Comments
 (0)