import { CommandNode, CommandOptions, CommandOptionsWithCallback, NodeType, ProgramOrCommandChildren, } from './types'; import { ValidOptions } from './types-internal'; import { getNodeChildren, serializeOptions, validateName, withDefault, } from './utils'; const validOptions = { alias: { type: 'string', }, description: { type: 'string', default: '', }, usage: { type: 'string', default: '', }, callback: { type: 'function', }, examples: { type: 'array', default: [], }, } satisfies ValidOptions; export function Command( name: N, options: CommandOptionsWithCallback, ...children: C ): CommandNode; export function Command( name: N, options?: CommandOptions | CommandOptionsWithCallback | null, ...children: C ): CommandNode; export function Command( name: N, options?: CommandOptions | CommandOptionsWithCallback | null, ...children: C ): CommandNode { validateName(name); const finalOptions = serializeOptions(withDefault(options, {}), validOptions); return { _type: NodeType.COMMAND, name, options: finalOptions, ...getNodeChildren(children), }; }