fix(cli/status): validate --interval only when --watch is used
The --interval flag is only relevant when --watch is enabled. Previously, passing `--interval 0` without `--watch` threw an error, whereas `--interval 5` was silently ignored. Now, invalid intervals are ignored when `--watch` is omitted, ensuring consistent behavior. Also adds a test case to prevent regression.
This commit is contained in:
parent
5a186fbb7f
commit
10a41cfafa
|
|
@ -605,6 +605,21 @@ describe("status command", () => {
|
|||
expect(errors).toContain("--interval must be a positive integer");
|
||||
});
|
||||
|
||||
it("ignores --interval entirely when --watch is not set", async () => {
|
||||
mockTmux.mockResolvedValue(null);
|
||||
mockSessionManager.list.mockResolvedValue([]);
|
||||
|
||||
// Invalid value (0) should NOT cause an error without --watch
|
||||
await expect(
|
||||
program.parseAsync(["node", "test", "status", "--interval", "0"]),
|
||||
).resolves.not.toThrow();
|
||||
|
||||
// Valid value should also be silently ignored without --watch
|
||||
await expect(
|
||||
program.parseAsync(["node", "test", "status", "--interval", "10"]),
|
||||
).resolves.not.toThrow();
|
||||
});
|
||||
|
||||
it("schedules watch refreshes with the requested interval", async () => {
|
||||
mockTmux.mockResolvedValue(null);
|
||||
setIntervalSpy = vi.spyOn(globalThis, "setInterval").mockImplementation(() => 1 as never);
|
||||
|
|
|
|||
|
|
@ -243,11 +243,13 @@ export function registerStatus(program: Command): void {
|
|||
}
|
||||
|
||||
let watchIntervalSeconds = DEFAULT_WATCH_INTERVAL_SECONDS;
|
||||
try {
|
||||
watchIntervalSeconds = parseWatchIntervalSeconds(opts.interval);
|
||||
} catch (err) {
|
||||
console.error(chalk.red(err instanceof Error ? err.message : String(err)));
|
||||
process.exit(1);
|
||||
if (opts.watch) {
|
||||
try {
|
||||
watchIntervalSeconds = parseWatchIntervalSeconds(opts.interval);
|
||||
} catch (err) {
|
||||
console.error(chalk.red(err instanceof Error ? err.message : String(err)));
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
const renderStatus = async (refreshing = false): Promise<void> => {
|
||||
|
|
|
|||
Loading…
Reference in New Issue