mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-11-18 16:08:56 +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>
43 lines
1.2 KiB
TypeScript
43 lines
1.2 KiB
TypeScript
import type { CommandDef } from "citty";
|
|
|
|
type LazyCommandDef = CommandDef | (() => CommandDef | Promise<CommandDef>);
|
|
|
|
export interface ResolvedCommandUsage {
|
|
command: CommandDef;
|
|
parent?: CommandDef;
|
|
path: string[];
|
|
unknownSubcommand?: string;
|
|
}
|
|
|
|
async function loadSubcommand(command: CommandDef, name: string): Promise<CommandDef | undefined> {
|
|
const subcommands = command.subCommands as Record<string, LazyCommandDef> | undefined;
|
|
const candidate = subcommands?.[name];
|
|
if (!candidate) return undefined;
|
|
return typeof candidate === "function" ? candidate() : candidate;
|
|
}
|
|
|
|
/** Resolve the deepest adjacent citty subcommand named by argv. */
|
|
export async function resolveCommandUsage(
|
|
root: CommandDef,
|
|
argv: readonly string[],
|
|
): Promise<ResolvedCommandUsage> {
|
|
let command = root;
|
|
let parent: CommandDef | undefined;
|
|
const path: string[] = [];
|
|
for (const argument of argv) {
|
|
if (argument.startsWith("-")) break;
|
|
const child = await loadSubcommand(command, argument);
|
|
if (!child)
|
|
return {
|
|
command,
|
|
parent,
|
|
path,
|
|
unknownSubcommand: command.subCommands ? argument : undefined,
|
|
};
|
|
parent = command;
|
|
command = child;
|
|
path.push(argument);
|
|
}
|
|
return { command, parent, path };
|
|
}
|