mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-11-18 07:50:13 +00:00
* fix(cli): add help [cmd], suggest the closest command or flag, and quiet the nags
`hyperframes help` printed "Unknown command help" with raw ANSI codes and no
suggestion. It is now an alias: `help [cmd...]` is `[cmd...] --help`.
An unknown command (at the root or inside a group like `cloud`) prints
"Unknown command: rendr", "Did you mean 'hyperframes render'?" and the group's
usage, all on stderr, and exits 2. An unknown flag suggests the flag it most
likely means ("Did you mean --output?"). Usage text printed for a usage error
now goes to stderr instead of stdout, and citty's colors are stripped from
help whenever this CLI's own colors are off.
No update, skills or app-history notice is appended to a usage error. The
skills notice shows at most once a day per project (timestamps in
~/.hyperframes/skills-notice.json) and, in an unattended run, only when a core
skill is missing.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
* fix(cli): reject an unknown top-level command without loading every command
citty looks for an alias on every registered command before it reports an
unknown name, which loads all of them. From a source checkout without the
studio packages built, that meant `hyperframes rendr` failed in preview's
build check with exit 1 instead of suggesting `render`. The name is now
checked against the registry first.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
* fix(cli): help with a mistyped subcommand reports it like the command itself
`hyperframes help cloud rendr` printed cloud's help and exited 0, while
`hyperframes cloud rendr` exits 2 with a suggestion. Both now exit 2 with the
suggestion. A group that also takes positional arguments (timeline takes a
project directory) still shows its help for a word it does not know.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
65 lines
2.3 KiB
TypeScript
65 lines
2.3 KiB
TypeScript
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);
|
|
});
|
|
});
|
|
|
|
describe("resolveCommandUsage path and unknown words", () => {
|
|
const render = defineCommand({ meta: { name: "render" } });
|
|
const cloud = defineCommand({ meta: { name: "cloud" }, subCommands: { render } });
|
|
const root = defineCommand({ meta: { name: "hyperframes" }, subCommands: { cloud } });
|
|
|
|
it("returns the words that named the command", async () => {
|
|
expect((await resolveCommandUsage(root, ["cloud", "render", "x"])).path).toEqual([
|
|
"cloud",
|
|
"render",
|
|
]);
|
|
});
|
|
|
|
it("names the first word that is not a subcommand of a group", async () => {
|
|
const resolved = await resolveCommandUsage(root, ["cloud", "rendr"]);
|
|
expect(resolved.command).toBe(cloud);
|
|
expect(resolved.path).toEqual(["cloud"]);
|
|
expect(resolved.unknownSubcommand).toBe("rendr");
|
|
});
|
|
|
|
it("does not treat a leaf command's positional as an unknown command", async () => {
|
|
expect(
|
|
(await resolveCommandUsage(root, ["cloud", "render", "./dir"])).unknownSubcommand,
|
|
).toBeUndefined();
|
|
});
|
|
});
|