UNPKG

2.8 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 */
45 static run: Config.Command.Class['run'];
46 id: string | undefined;
47 protected debug: (...args: any[]) => void;
48 constructor(argv: string[], config: Config.IConfig);
49 get ctor(): typeof Command;
50 _run<T>(): Promise<T | undefined>;
51 exit(code?: number): never;
52 warn(input: string | Error): void;
53 error(input: string | Error, options: {
54 code?: string;
55 exit: false;
56 } & PrettyPrintableError): void;
57 error(input: string | Error, options?: {
58 code?: string;
59 exit?: number;
60 } & PrettyPrintableError): never;
61 log(message?: string, ...args: any[]): void;
62 /**
63 * actual command run code goes here
64 */
65 abstract run(): PromiseLike<any>;
66 protected init(): Promise<any>;
67 protected parse<F, A extends {
68 [name: string]: any;
69 }>(options?: Parser.Input<F>, argv?: string[]): Parser.Output<F, A>;
70 protected catch(err: any): Promise<any>;
71 protected finally(_: Error | undefined): Promise<any>;
72 protected _help(): never;
73 protected _helpOverride(): boolean;
74 protected _version(): never;
75}