Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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;
},
});

Expand Down
6 changes: 4 additions & 2 deletions src/schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
15 changes: 15 additions & 0 deletions test/cli-describe.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[]) {
Expand Down