UNPKG

@lodestar/utils

Version:

Utilities required across multiple lodestar packages

36 lines 1.53 kB
import type { Argv, Options } from "yargs"; export interface CliExample { command: string; title?: string; description?: string; } export interface CliOptionDefinition<T = any> extends Options { example?: Omit<CliExample, "title">; type: T extends string ? "string" : T extends number ? "number" : T extends boolean ? "boolean" : T extends Array<unknown> ? "array" : never; } export type CliCommandOptions<OwnArgs> = Required<{ [K in keyof OwnArgs]: undefined extends OwnArgs[K] ? CliOptionDefinition<OwnArgs[K]> : // If arg cannot be undefined it must specify a default value or be provided by the user CliOptionDefinition<OwnArgs[K]> & (Required<Pick<Options, "default">> | { demandOption: true; }); }>; export interface CliCommand<OwnArgs = Record<never, never>, ParentArgs = Record<never, never>, R = any> { command: string; describe: string; /** * The folder in docs/pages that the cli.md should be placed in. If not provided no * cli flags page will be generated for the command */ docsFolder?: string; examples?: CliExample[]; options?: CliCommandOptions<OwnArgs>; subcommands?: CliCommand<any, OwnArgs & ParentArgs>[]; handler?: (args: OwnArgs & ParentArgs) => Promise<R>; } /** * Register a CliCommand type to yargs. Recursively registers subcommands too. * @param yargs * @param cliCommand */ export declare function registerCommandToYargs(yargs: Argv, cliCommand: CliCommand<any, any>): void; //# sourceMappingURL=command.d.ts.map