Skip to content

Commit 80c0822

Browse files
committed
fix(cli): keep search limit parser out of helpers
1 parent bcbda6a commit 80c0822

7 files changed

Lines changed: 40 additions & 29 deletions

File tree

‎src/cli/plugins-cli.lazy.test.ts‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,31 @@ describe("plugins cli lazy runtime boundary", () => {
7272
expect(searchLoaded).toBe(false);
7373
});
7474

75+
it("parses valid plugins search limits for the search action", async () => {
76+
const runPluginsSearchCommand = vi.fn().mockResolvedValue(undefined);
77+
vi.doMock("./plugins-search-command.js", () => ({
78+
runPluginsSearchCommand,
79+
}));
80+
81+
const { registerPluginsCli } = await import("./plugins-cli.js");
82+
const program = new Command();
83+
program.exitOverride();
84+
program.configureOutput({
85+
writeErr: () => {},
86+
writeOut: () => {},
87+
});
88+
registerPluginsCli(program);
89+
90+
await program.parseAsync(["plugins", "search", "calendar", "--limit", "+10", "--json"], {
91+
from: "user",
92+
});
93+
94+
expect(runPluginsSearchCommand).toHaveBeenCalledWith(
95+
["calendar"],
96+
expect.objectContaining({ json: true, limit: 10 }),
97+
);
98+
});
99+
75100
it("loads the plugins runtime for runtime-backed actions", async () => {
76101
const runPluginsRegistryCommand = vi.fn().mockResolvedValue(undefined);
77102
const runtimeLoaded = vi.fn();

‎src/cli/plugins-cli.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { formatDocsLink } from "../terminal/links.js";
33
import { theme } from "../terminal/theme.js";
44
import type { PluginInspectOptions } from "./plugins-inspect-command.js";
55
import type { PluginsListOptions } from "./plugins-list-command.js";
6-
import { parsePositiveIntegerOption } from "./program/helpers.js";
6+
import { parsePositiveIntegerOption } from "./positive-integer-option.js";
77
import { applyParentDefaultHelpAction } from "./program/parent-default-help.js";
88

99
export type PluginUpdateOptions = {

‎src/cli/positive-integer-option.ts‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { InvalidArgumentError } from "commander";
2+
import { parseStrictPositiveInteger } from "../infra/parse-finite-number.js";
3+
4+
export function parsePositiveIntegerOption(value: string): number {
5+
const parsed = parseStrictPositiveInteger(value);
6+
if (parsed === undefined) {
7+
throw new InvalidArgumentError("Expected a positive integer.");
8+
}
9+
return parsed;
10+
}

‎src/cli/program/helpers.test.ts‎

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { Command } from "commander";
22
import { describe, expect, it } from "vitest";
33
import {
44
collectOption,
5-
parsePositiveIntegerOption,
65
parsePositiveIntOrUndefined,
76
parseStrictPositiveIntOrUndefined,
87
resolveActionArgs,
@@ -54,21 +53,6 @@ describe("program helpers", () => {
5453
expect(parseStrictPositiveIntOrUndefined(value)).toBe(expected);
5554
});
5655

57-
it.each([
58-
{ value: "1", expected: 1 },
59-
{ value: " 25 ", expected: 25 },
60-
{ value: "9007199254740991", expected: Number.MAX_SAFE_INTEGER },
61-
])("parsePositiveIntegerOption(%j)", ({ value, expected }) => {
62-
expect(parsePositiveIntegerOption(value)).toBe(expected);
63-
});
64-
65-
it.each(["", "0", "-1", "1abc", "5.5", "1e3", "9007199254740992"])(
66-
"rejects invalid positive integer option value %j",
67-
(value) => {
68-
expect(() => parsePositiveIntegerOption(value)).toThrow("Expected a positive integer.");
69-
},
70-
);
71-
7256
it("resolveActionArgs returns args when command has arg array", () => {
7357
const command = new Command();
7458
(command as Command & { args?: string[] }).args = ["one", "two"];

‎src/cli/program/helpers.ts‎

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { InvalidArgumentError, type Command } from "commander";
1+
import type { Command } from "commander";
22
import { parseStrictPositiveInteger } from "../../infra/parse-finite-number.js";
33

44
export function collectOption(value: string, previous: string[] = []): string[] {
@@ -30,14 +30,6 @@ export function parseStrictPositiveIntOrUndefined(value: unknown): number | unde
3030
return parseStrictPositiveInteger(value);
3131
}
3232

33-
export function parsePositiveIntegerOption(value: string): number {
34-
const parsed = parseStrictPositiveInteger(value);
35-
if (parsed === undefined) {
36-
throw new InvalidArgumentError("Expected a positive integer.");
37-
}
38-
return parsed;
39-
}
40-
4133
export function resolveActionArgs(actionCommand?: Command): string[] {
4234
if (!actionCommand) {
4335
return [];

‎src/cli/skills-cli.commands.test.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -277,11 +277,11 @@ describe("skills cli commands", () => {
277277
},
278278
]);
279279

280-
await runCommand(["skills", "search", "calendar"]);
280+
await runCommand(["skills", "search", "calendar", "--limit", "+10"]);
281281

282282
expect(searchSkillsFromClawHubMock).toHaveBeenCalledWith({
283283
query: "calendar",
284-
limit: undefined,
284+
limit: 10,
285285
});
286286
expect(
287287
runtimeLogs.some((line) => line.includes("calendar v1.2.3 Calendar")),

‎src/cli/skills-cli.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import { formatDocsLink } from "../terminal/links.js";
2121
import { theme } from "../terminal/theme.js";
2222
import { CONFIG_DIR } from "../utils.js";
2323
import { resolveOptionFromCommand } from "./cli-utils.js";
24-
import { parsePositiveIntegerOption } from "./program/helpers.js";
24+
import { parsePositiveIntegerOption } from "./positive-integer-option.js";
2525
import { formatSkillInfo, formatSkillsCheck, formatSkillsList } from "./skills-cli.format.js";
2626

2727
export type {

0 commit comments

Comments
 (0)