command.d.ts
3.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/// <reference types="node" />
import { Dictionary } from './common-types';
import { Middleware } from './middleware';
import { Positional } from './parse-command';
import { RequireDirectoryOptions } from 'require-directory';
import { UsageInstance } from './usage';
import { ValidationInstance } from './validation';
import { YargsInstance, Options, OptionDefinition, Context, Arguments, DetailedArguments } from './yargs';
export declare function command(yargs: YargsInstance, usage: UsageInstance, validation: ValidationInstance, globalMiddleware?: Middleware[]): CommandInstance;
/** Instance of the command module. */
export interface CommandInstance {
addDirectory(dir: string, context: Context, req: NodeRequireFunction, callerFile: string, opts?: RequireDirectoryOptions<any>): void;
addHandler(handler: CommandHandlerDefinition): void;
addHandler(cmd: string | string[], description: CommandHandler['description'], builder?: CommandBuilderDefinition | CommandBuilder, handler?: CommandHandlerCallback, commandMiddleware?: Middleware[], deprecated?: boolean): void;
cmdToParseOptions(cmdString: string): Positionals;
freeze(): void;
getCommandHandlers(): Dictionary<CommandHandler>;
getCommands(): string[];
hasDefaultCommand(): boolean;
reset(): CommandInstance;
runCommand(command: string | null, yargs: YargsInstance, parsed: DetailedArguments, commandIndex?: number): Arguments | Promise<Arguments>;
runDefaultBuilderOn(yargs: YargsInstance): void;
unfreeze(): void;
}
export interface CommandHandlerDefinition extends Partial<Pick<CommandHandler, 'deprecated' | 'description' | 'handler' | 'middlewares'>> {
aliases?: string[];
builder?: CommandBuilder | CommandBuilderDefinition;
command?: string | string[];
desc?: CommandHandler['description'];
describe?: CommandHandler['description'];
}
export declare function isCommandHandlerDefinition(cmd: string | string[] | CommandHandlerDefinition): cmd is CommandHandlerDefinition;
export interface CommandBuilderDefinition {
builder?: CommandBuilder;
deprecated?: boolean;
handler: CommandHandlerCallback;
middlewares?: Middleware[];
}
export declare function isCommandBuilderDefinition(builder?: CommandBuilder | CommandBuilderDefinition): builder is CommandBuilderDefinition;
export interface CommandHandlerCallback {
(argv: Arguments): any;
}
export interface CommandHandler {
builder: CommandBuilder;
demanded: Positional[];
deprecated?: boolean;
description?: string | false;
handler: CommandHandlerCallback;
middlewares: Middleware[];
optional: Positional[];
original: string;
}
export declare type CommandBuilder = CommandBuilderCallback | Dictionary<OptionDefinition>;
interface CommandBuilderCallback {
(y: YargsInstance): YargsInstance | void;
}
export declare function isCommandBuilderCallback(builder: CommandBuilder): builder is CommandBuilderCallback;
interface Positionals extends Pick<Options, 'alias' | 'array' | 'default'> {
demand: Dictionary<boolean>;
}
export interface FinishCommandHandler {
(handlerResult: any): any;
}
export {};