refactor(cli): centralize process lifecycle

This commit is contained in:
James
2026-07-20 09:04:03 -07:00
parent 6ad738b580
commit 3aa2404747
71 changed files with 812 additions and 434 deletions
@@ -0,0 +1,38 @@
import { describe, expect, it, vi } from "vitest";
import { defineCommand } from "citty";
import { resolveCommandUsage } from "./commandUsageResolution.js";
describe("resolveCommandUsage", () => {
it("resolves the deepest lazy subcommand and its immediate parent", async () => {
const render = defineCommand({
meta: { name: "render" },
args: { fps: { type: "string" } },
});
const loadRender = vi.fn(async () => render);
const cloud = defineCommand({
meta: { name: "cloud" },
subCommands: { render: loadRender },
});
const root = defineCommand({
meta: { name: "hyperframes" },
subCommands: { cloud: async () => cloud },
});
const resolved = await resolveCommandUsage(root, ["cloud", "render", "--help"]);
expect(resolved.command).toBe(render);
expect(resolved.parent).toBe(cloud);
expect(loadRender).toHaveBeenCalledTimes(1);
});
it("keeps group and root help at the requested level", async () => {
const cloud = defineCommand({ meta: { name: "cloud" }, subCommands: {} });
const root = defineCommand({
meta: { name: "hyperframes" },
subCommands: { cloud: async () => cloud },
});
expect((await resolveCommandUsage(root, ["cloud", "--help"])).command).toBe(cloud);
expect((await resolveCommandUsage(root, ["--help"])).command).toBe(root);
});
});