1 | import Macroable from '@poppinss/macroable';
|
2 | import type { Prompt } from '@poppinss/prompts';
|
3 | import type { Colors } from '@poppinss/cliui/types';
|
4 | import type { Kernel } from '../kernel.js';
|
5 | import type { Flag, Argument, ParsedOutput, UIPrimitives, CommandOptions, CommandMetaData, FlagsParserOptions, ArgumentsParserOptions } from '../types.js';
|
6 | /**
|
7 | * The base command sets the foundation for defining ace commands.
|
8 | * Every command should inherit from the base command.
|
9 | */
|
10 | export declare class BaseCommand extends Macroable {
|
11 | protected kernel: Kernel<any>;
|
12 | protected parsed: ParsedOutput;
|
13 | ui: UIPrimitives;
|
14 | prompt: Prompt;
|
15 | static booted: boolean;
|
16 | /**
|
17 | * Configuration options accepted by the command
|
18 | */
|
19 | static options: CommandOptions;
|
20 | /**
|
21 | * A collection of aliases for the command
|
22 | */
|
23 | static aliases: string[];
|
24 | /**
|
25 | * The command name one can type to run the command
|
26 | */
|
27 | static commandName: string;
|
28 | /**
|
29 | * The command description
|
30 | */
|
31 | static description: string;
|
32 | /**
|
33 | * The help text for the command. Help text can be a multiline
|
34 | * string explaining the usage of command
|
35 | */
|
36 | static help?: string | string[];
|
37 | /**
|
38 | * Registered arguments
|
39 | */
|
40 | static args: Argument[];
|
41 | /**
|
42 | * Registered flags
|
43 | */
|
44 | static flags: Flag[];
|
45 | /**
|
46 | * Define static properties on the class. During inheritance, certain
|
47 | * properties must inherit from the parent.
|
48 | */
|
49 | static boot(): void;
|
50 | /**
|
51 | * Specify the argument the command accepts. The arguments via the CLI
|
52 | * will be accepted in the same order as they are defined.
|
53 | *
|
54 | * Mostly, you will be using the `@args` decorator to define the arguments.
|
55 | *
|
56 | * ```ts
|
57 | * Command.defineArgument('entity', { type: 'string' })
|
58 | * ```
|
59 | */
|
60 | static defineArgument(name: string, options: Partial<Argument> & {
|
61 | type: 'string' | 'spread';
|
62 | }): void;
|
63 | /**
|
64 | * Specify a flag the command accepts.
|
65 | *
|
66 | * Mostly, you will be using the `@flags` decorator to define a flag.
|
67 | *
|
68 | * ```ts
|
69 | * Command.defineFlag('connection', { type: 'string', required: true })
|
70 | * ```
|
71 | */
|
72 | static defineFlag(name: string, options: Partial<Flag> & {
|
73 | type: 'string' | 'boolean' | 'array' | 'number';
|
74 | }): void;
|
75 | /**
|
76 | * Returns the options for parsing flags and arguments
|
77 | */
|
78 | static getParserOptions(options?: FlagsParserOptions): {
|
79 | flagsParserOptions: Required<FlagsParserOptions>;
|
80 | argumentsParserOptions: ArgumentsParserOptions[];
|
81 | };
|
82 | /**
|
83 | * Serializes the command to JSON. The return value satisfies the
|
84 | * {@link CommandMetaData}
|
85 | */
|
86 | static serialize(): CommandMetaData;
|
87 | /**
|
88 | * Validate the yargs parsed output againts the command.
|
89 | */
|
90 | static validate(parsedOutput: ParsedOutput): void;
|
91 | /**
|
92 | * Check if a command has been hypdrated
|
93 | */
|
94 | protected hydrated: boolean;
|
95 | /**
|
96 | * The exit code for the command
|
97 | */
|
98 | exitCode?: number;
|
99 | /**
|
100 | * The error raised at the time of the executing the command.
|
101 | * The value is undefined if no error is raised.
|
102 | */
|
103 | error?: any;
|
104 | /**
|
105 | * The result property stores the return value of the "run"
|
106 | * method (unless commands sets it explicitly)
|
107 | */
|
108 | result?: any;
|
109 | /**
|
110 | * Logger to log messages
|
111 | */
|
112 | get logger(): import("@poppinss/cliui").Logger;
|
113 | /**
|
114 | * Add colors to console messages
|
115 | */
|
116 | get colors(): Colors;
|
117 | /**
|
118 | * Is the current command the main command executed from the
|
119 | * CLI
|
120 | */
|
121 | get isMain(): boolean;
|
122 | /**
|
123 | * Reference to the command name
|
124 | */
|
125 | get commandName(): string;
|
126 | /**
|
127 | * Reference to the command options
|
128 | */
|
129 | get options(): CommandOptions;
|
130 | /**
|
131 | * Reference to the command args
|
132 | */
|
133 | get args(): Argument[];
|
134 | /**
|
135 | * Reference to the command flags
|
136 | */
|
137 | get flags(): Flag[];
|
138 | constructor(kernel: Kernel<any>, parsed: ParsedOutput, ui: UIPrimitives, prompt: Prompt);
|
139 | /**
|
140 | * Hydrate command by setting class properties from
|
141 | * the parsed output
|
142 | */
|
143 | hydrate(): void;
|
144 | /**
|
145 | * The run method should include the implementation for the
|
146 | * command.
|
147 | */
|
148 | run(..._: any[]): Promise<any>;
|
149 | /**
|
150 | * Executes the commands by running the command's run method.
|
151 | */
|
152 | exec(): Promise<any>;
|
153 | /**
|
154 | * JSON representation of the command
|
155 | */
|
156 | toJSON(): {
|
157 | commandName: string;
|
158 | options: CommandOptions;
|
159 | args: any[];
|
160 | flags: {
|
161 | [argName: string]: any;
|
162 | };
|
163 | error: any;
|
164 | result: any;
|
165 | exitCode: number | undefined;
|
166 | };
|
167 | /**
|
168 | * Assert the command exists with a given exit code
|
169 | */
|
170 | assertExitCode(code: number): void;
|
171 | /**
|
172 | * Assert the command exists with a given exit code
|
173 | */
|
174 | assertNotExitCode(code: number): void;
|
175 | /**
|
176 | * Assert the command exists with zero exit code
|
177 | */
|
178 | assertSucceeded(): void;
|
179 | /**
|
180 | * Assert the command exists with non-zero exit code
|
181 | */
|
182 | assertFailed(): void;
|
183 | /**
|
184 | * Assert command to log the expected message
|
185 | */
|
186 | assertLog(message: string, stream?: 'stdout' | 'stderr'): void;
|
187 | /**
|
188 | * Assert command to log the expected message
|
189 | */
|
190 | assertLogMatches(matchingRegex: RegExp, stream?: 'stdout' | 'stderr'): void;
|
191 | /**
|
192 | * Assert the command prints a table to stdout
|
193 | */
|
194 | assertTableRows(rows: string[][]): void;
|
195 | }
|