diff --git a/src/cli.ts b/src/cli.ts index 9f47427..5248118 100644 --- a/src/cli.ts +++ b/src/cli.ts @@ -20,7 +20,7 @@ import { listSessions, syncSessions, } from "./commands/sessions.js"; -import { fetchServiceList, fetchServices } from "./commands/services.js"; +import { fetchServices } from "./commands/services.js"; import { handleCompatCommand } from "./compat.js"; import { completionsArgs, @@ -230,11 +230,11 @@ cli.command("services", { alias: globalAlias, output: servicesOutput, async run({ args, options }) { - if (args.serviceId === "list" && !options.search) return fetchServiceList(); - return fetchServices({ + const result = await fetchServices({ search: options.search, serviceId: args.serviceId === "list" ? undefined : args.serviceId, }); + return Array.isArray(result) ? { services: result } : result; }, }); diff --git a/src/schemas.ts b/src/schemas.ts index a812040..192e4f0 100644 --- a/src/schemas.ts +++ b/src/schemas.ts @@ -329,9 +329,11 @@ export const servicesOptions = z.object({ search: z.string().optional().describe("Search by name, description, tags, or category"), }); -export const servicesOutput = z.union([z.array(serviceOutput), serviceDetailOutput]); +export const servicesListOutput = z.object({ + services: z.array(serviceOutput), +}); -export const servicesListOutput = z.array(serviceOutput); +export const servicesOutput = z.union([servicesListOutput, serviceDetailOutput]); export const completionsArgs = z.object({ shell: z.enum(["bash", "elvish", "fish", "powershell", "zsh"]).optional(), diff --git a/test/cli-describe.test.ts b/test/cli-describe.test.ts index 5f6c9c4..5da532d 100644 --- a/test/cli-describe.test.ts +++ b/test/cli-describe.test.ts @@ -118,6 +118,21 @@ describe("generated CLI metadata", () => { browser: false, }); }); + + it("returns services wrapped in an object for services command schema", async () => { + const output = await walletCli(["services", "--schema", "--format", "json"]); + const schema = JSON.parse(output) as { + output: { anyOf?: { properties?: { services?: unknown } }[] }; + }; + expect(schema.output.anyOf?.[0]?.properties).toHaveProperty("services"); + }); + + it("returns services list wrapped in an object when executed with --format json", async () => { + const output = await walletCli(["services", "--format", "json"]); + const json = JSON.parse(output) as { services?: unknown }; + expect(json).toHaveProperty("services"); + expect(Array.isArray(json.services)).toBe(true); + }); }); async function walletCli(args: string[]) {