UNPKG

yargs-file-commands

Version:

A yargs helper function that lets you define your commands structure via directory and file naming conventions.

39 lines (38 loc) 1.47 kB
import type { ArgumentsCamelCase, Argv, CommandModule, InferredOptionTypes, Options } from 'yargs'; export type DefineCommandResult<T = {}, U = {}> = CommandModule<T, U>; /** * Helper to define a command with type inference for arguments. * * @example * ```typescript * export const command = defineCommand({ * command: 'my-command', * builder: (yargs) => yargs.option('name', { type: 'string', demandOption: true }), * handler: (argv) => { * // argv.name is correctly typed as string * console.log(argv.name); * }, * }); * ``` */ export declare function defineCommand<T = {}, U = {}>(module: { command?: string | ReadonlyArray<string>; aliases?: string | ReadonlyArray<string>; describe?: string | false; deprecated?: boolean | string; builder: (yargs: Argv<T>) => Argv<U> | PromiseLike<Argv<U>>; handler: (args: ArgumentsCamelCase<U>) => void | Promise<void>; }): DefineCommandResult<T, U>; /** * Helper to define a command with type inference for arguments using an options object builder. */ export declare function defineCommand<O extends { [key: string]: Options; }, T = {}>(module: { command?: string | ReadonlyArray<string>; aliases?: string | ReadonlyArray<string>; describe?: string | false; deprecated?: boolean | string; builder: O; handler: (args: ArgumentsCamelCase<InferredOptionTypes<O>>) => void | Promise<void>; }): DefineCommandResult<T, InferredOptionTypes<O>>;