import { IgnoreFunction, Flags as Flags$1, TypeFlag } from 'type-flag'; export { TypeFlag } from 'type-flag'; import { Options } from 'terminal-columns'; type CommandOptions = { /** Name of the command used to invoke it. Also displayed in `--help` output. */ name: string; /** Aliases for the command used to invoke it. Also displayed in `--help` output. */ alias?: string | string[]; /** Parameters accepted by the command. Parameters must be in the following formats: - Required parameter: `` - Optional parameter: `[parameter name]` - Required spread parameter: `` - Optional spread parameter: `[parameter name...]` */ parameters?: Parameters; /** Flags accepted by the command */ flags?: Flags; /** Options to configure the help documentation. Pass in `false` to disable handling `--help, -h`. */ help?: false | HelpOptions; /** * Which argv elements to ignore from parsing */ ignoreArgv?: IgnoreFunction; /** * When enabled, prints an error and exits if unknown flags are passed. * Suggests the closest matching flag name when possible. * Inherits from parent CLI if not specified. */ strictFlags?: boolean; /** * Enable `--no-` negation for boolean flags. * * When enabled, `--no-verbose` is equivalent to `--verbose=false`. * Only applies to flags defined as `Boolean`. * Inherits from parent CLI if not specified. */ booleanFlagNegation?: boolean; }; declare function command, Parameters extends string[]>(options: Readonly & CommandOptions<[...Parameters]>, callback?: CallbackFunction>): Command>; type Command = { readonly options: Options; readonly callback?: CallbackFunction; [parsedType]: ParsedType; }; type FlagData = { name: string; flag: Flags[string]; flagFormatted: string; aliasesEnabled: boolean; aliasFormatted: string | undefined; }; type TypeFunction = (value: any) => any; type HelpDocumentNodeOrString = string | HelpDocumentNode; declare class Renderers { text(text: string): string; bold(text: string): string; indentText({ text, spaces }: { text: string; spaces: number; }): string; heading(text: string): string; section({ title, body, indentBody, }: { title?: string; body?: string; indentBody?: number; }): string; table({ tableData, tableOptions, tableBreakpoints, }: { tableData: string[][]; tableOptions?: Options; tableBreakpoints?: Record; }): string; flagParameter(typeFunction: TypeFunction | readonly [TypeFunction]): string; flagOperator(_: FlagData): string; flagName(flagData: FlagData): string; flagDefault(value: any): string; flagDescription({ flag }: FlagData): string; render(nodes: (HelpDocumentNodeOrString | HelpDocumentNodeOrString[])): string; } declare const parsedType: unique symbol; type Flags = Flags$1<{ /** Description to be used in help output @example ``` description: 'Unit of output (metric, imperial)', ``` */ description?: string; /** Placeholder label to be used in help output @example Required value ``` placeholder: '' ``` */ placeholder?: string; }>; type CallbackFunction = (parsed: { [Key in keyof Parsed]: Parsed[Key]; }) => void | Promise; type HasVersion = (Options extends { version: string; } ? Options['flags'] & { version: BooleanConstructor; } : Options['flags']); type HasHelp = (Options extends { help: false; } ? Options['flags'] : Options['flags'] & { help: BooleanConstructor; }); type HasHelpOrVersion = (HasVersion & HasHelp); type HelpDocumentNode = { id?: string; type: Types; data: any; }; type HelpOptions = { /** Version of the script displayed in `--help` output. Use to avoid enabling `--version` flag. */ version?: string; /** Description of the script or command to display in `--help` output. */ description?: string; /** Usage code examples to display in `--help` output. */ usage?: false | string | string[]; /** Example code snippets to display in `--help` output. */ examples?: string | string[]; /** Function to customize the help document before it is logged. */ render?: (nodes: HelpDocumentNode[], renderers: Renderers) => string; }; type CliOptions = { /** Name of the script displayed in `--help` output. */ name?: string; /** Version of the script displayed in `--version` and `--help` outputs. */ version?: string; /** Parameters accepted by the script. Parameters must be in the following formats: - Required parameter: `` - Optional parameter: `[parameter name]` - Required spread parameter: `` - Optional spread parameter: `[parameter name...]` */ parameters?: Parameters; /** Commands to register to the script. */ commands?: Commands; /** Flags accepted by the script */ flags?: Flags; /** Options to configure the help documentation. Pass in `false` to disable handling `--help, -h`. */ help?: false | HelpOptions; /** * Which argv elements to ignore from parsing */ ignoreArgv?: IgnoreFunction; /** * When enabled, prints an error and exits if unknown flags are passed. * Suggests the closest matching flag name when possible. */ strictFlags?: boolean; /** * Enable `--no-` negation for boolean flags. * * When enabled, `--no-verbose` is equivalent to `--verbose=false`. * Only applies to flags defined as `Boolean`. */ booleanFlagNegation?: boolean; }; type AlphabetLowercase = 'a' | 'b' | 'c' | 'd' | 'e' | 'f' | 'g' | 'h' | 'i' | 'j' | 'k' | 'l' | 'm' | 'n' | 'o' | 'p' | 'q' | 'r' | 's' | 't' | 'u' | 'v' | 'w' | 'x' | 'y' | 'z'; type Numeric = '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9'; type AlphaNumeric = AlphabetLowercase | Uppercase | Numeric; type CamelCase = (Word extends `${infer FirstCharacter}${infer Rest}` ? (FirstCharacter extends AlphaNumeric ? `${FirstCharacter}${CamelCase}` : Capitalize>) : Word); type StripBrackets = (Parameter extends `<${infer ParameterName}>` | `[${infer ParameterName}]` ? (ParameterName extends `${infer SpreadName}...` ? SpreadName : ParameterName) : never); type ParameterType = (Parameter extends `<${infer _ParameterName}...>` | `[${infer _ParameterName}...]` ? string[] : Parameter extends `<${infer _ParameterName}>` ? string : Parameter extends `[${infer _ParameterName}]` ? string | undefined : never); type WithCommand = { command: CommandName; } & Options; type TypeFlagWrapper = TypeFlag> & { _: { [Parameter in Parameters[number] as CamelCase>]: ParameterType; }; showHelp: (options?: HelpOptions) => void; showVersion: () => void; }; type ParseArgv = (CommandName extends '' ? TypeFlagWrapper : WithCommand, CommandName>); /** * Helper type to reject unknown properties in cli() options. * Maps any key not in CliOptions to `never`, causing a type error * when excess properties are passed. */ type StrictOptions = T & Record, never>; /** * Helper type to conditionally add Promise to return type * only when callback returns a Promise. */ type MaybePromise = CallbackReturn extends Promise ? Result & Promise : Result; declare function cli, Parameters extends string[]>(options: StrictOptions & CliOptions & { commands?: undefined; }, callback?: undefined, argv?: string[]): { [Key in keyof ParseArgv]: ParseArgv[Key]; }; declare function cli, Parameters extends string[], CallbackReturn extends void | Promise>(options: StrictOptions & CliOptions & { commands?: undefined; }, callback: (parsed: ParseArgv) => CallbackReturn, argv?: string[]): MaybePromise<{ [Key in keyof ParseArgv]: ParseArgv[Key]; }, CallbackReturn>; declare function cli, Commands extends Command[], Parameters extends string[]>(options: StrictOptions & CliOptions<[...Commands], [...Parameters]> & { commands: [...Commands]; }, callback?: undefined, argv?: string[]): ({ [Key in keyof ParseArgv]: ParseArgv[Key]; } | { [KeyA in keyof Commands]: (Commands[KeyA] extends Command ? ({ [KeyB in keyof Commands[KeyA][typeof parsedType]]: Commands[KeyA][typeof parsedType][KeyB]; }) : never); }[number]) & Promise; declare function cli, Commands extends Command[], Parameters extends string[]>(options: StrictOptions & CliOptions<[...Commands], [...Parameters]> & { commands: [...Commands]; }, callback: (parsed: ParseArgv) => void | Promise, argv?: string[]): (({ [Key in keyof ParseArgv]: ParseArgv[Key]; } | { [KeyA in keyof Commands]: (Commands[KeyA] extends Command ? ({ [KeyB in keyof Commands[KeyA][typeof parsedType]]: Commands[KeyA][typeof parsedType][KeyB]; }) : never); }[number]) & Promise); declare function cli(options: CliOptions, callback?: CallbackFunction, argv?: string[]): ParseArgv; export { Renderers, cli, command }; export type { Command, Flags };