UNPKG

2.83 kBTypeScriptView Raw
1import * as Config from '@oclif/config';
2import * as Parser from '@oclif/parser';
3import * as flags from './flags';
4import { PrettyPrintableError } from '@oclif/errors';
5/**
6 * An abstract class which acts as the base for each command
7 * in your project.
8 */
9export default abstract class Command {
10 argv: string[];
11 config: Config.IConfig;
12 static _base: string;
13 /** A command ID, used mostly in error or verbose reporting */
14 static id: string;
15 static title: string | undefined;
16 /**
17 * The tweet-sized description for your class, used in a parent-commands
18 * sub-command listing and as the header for the command help
19 */
20 static description: string | undefined;
21 /** hide the command from help? */
22 static hidden: boolean;
23 /** An override string (or strings) for the default usage documentation */
24 static usage: string | string[] | undefined;
25 static help: string | undefined;
26 /** An array of aliases for this command */
27 static aliases: string[];
28 /** When set to false, allows a variable amount of arguments */
29 static strict: boolean;
30 static parse: boolean;
31 /** A hash of flags for the command */
32 static flags?: flags.Input<any>;
33 /** An order-dependent array of arguments for the command */
34 static args?: Parser.args.Input;
35 static plugin: Config.IPlugin | undefined;
36 /** An array of example strings to show at the end of the command's help */
37 static examples: string[] | undefined;
38 static parserOptions: {};
39 /**
40 * instantiate and run the command
41 * @param {Config.Command.Class} this Class
42 * @param {string[]} argv argv
43 * @param {Config.LoadOptions} opts options
44 * @returns Promise<any>
45 */
46 static run: Config.Command.Class['run'];
47 id: string | undefined;
48 protected debug: (...args: any[]) => void;
49 constructor(argv: string[], config: Config.IConfig);
50 get ctor(): typeof Command;
51 _run<T>(): Promise<T | undefined>;
52 exit(code?: number): never;
53 warn(input: string | Error): void;
54 error(input: string | Error, options: {
55 code?: string;
56 exit: false;
57 } & PrettyPrintableError): void;
58 error(input: string | Error, options?: {
59 code?: string;
60 exit?: number;
61 } & PrettyPrintableError): never;
62 log(message?: string, ...args: any[]): void;
63 /**
64 * actual command run code goes here
65 */
66 abstract run(): PromiseLike<any>;
67 protected init(): Promise<any>;
68 protected parse<F, A extends {
69 [name: string]: any;
70 }>(options?: Parser.Input<F>, argv?: string[]): Parser.Output<F, A>;
71 protected catch(err: any): Promise<any>;
72 protected finally(_: Error | undefined): Promise<any>;
73 protected _help(): never;
74 protected _helpOverride(): boolean;
75 protected _version(): never;
76}