UNPKG

5 kBTypeScriptView Raw
1import { ApplicationContract } from '@ioc:Adonis/Core/Application';
2import { ManifestLoader } from '../Manifest/Loader';
3import { CommandFlag, KernelContract, CommandContract, ManifestCommand, RunHookCallback, FindHookCallback, GlobalFlagHandler, CommandConstructorContract } from '../Contracts';
4/**
5 * Ace kernel class is used to register, find and invoke commands by
6 * parsing `process.argv.splice(2)` value.
7 */
8export declare class Kernel implements KernelContract {
9 application: ApplicationContract;
10 /**
11 * Reference to hooks class to execute lifecycle
12 * hooks
13 */
14 private hooks;
15 /**
16 * Reference to the manifest loader. If defined, we will give preference
17 * to the manifest files.
18 */
19 private manifestLoader;
20 /**
21 * The command that started the process
22 */
23 private entryCommand?;
24 /**
25 * The state of the kernel
26 */
27 private state;
28 /**
29 * Exit handler for gracefully exiting the process
30 */
31 private exitHandler;
32 /**
33 * The default command that will be invoked when no command is
34 * defined
35 */
36 defaultCommand: CommandConstructorContract;
37 /**
38 * List of registered commands
39 */
40 commands: {
41 [name: string]: CommandConstructorContract;
42 };
43 aliases: {
44 [alias: string]: string;
45 };
46 /**
47 * List of registered flags
48 */
49 flags: {
50 [name: string]: CommandFlag & {
51 handler: GlobalFlagHandler;
52 };
53 };
54 /**
55 * The exit code for the process
56 */
57 exitCode?: number;
58 /**
59 * The error collected as part of the running commands or executing
60 * flags
61 */
62 error?: any;
63 constructor(application: ApplicationContract);
64 /**
65 * Executing global flag handlers. The global flag handlers are
66 * not async as of now, but later we can look into making them
67 * async.
68 */
69 private executeGlobalFlagsHandlers;
70 /**
71 * Returns an array of all registered commands
72 */
73 private getAllCommandsAndAliases;
74 /**
75 * Processes the args and sets values on the command instance
76 */
77 private processCommandArgsAndFlags;
78 /**
79 * Execute the main command. For calling commands within commands,
80 * one must call "kernel.exec".
81 */
82 private execMain;
83 /**
84 * Handles exiting the process
85 */
86 private exitProcess;
87 /**
88 * Register a before hook
89 */
90 before(action: 'run', callback: RunHookCallback): this;
91 before(action: 'find', callback: FindHookCallback): this;
92 /**
93 * Register an after hook
94 */
95 after(action: 'run', callback: RunHookCallback): this;
96 after(action: 'find', callback: FindHookCallback): this;
97 /**
98 * Register an array of command constructors
99 */
100 register(commands: CommandConstructorContract[]): this;
101 /**
102 * Register a global flag. It can be defined in combination with
103 * any command.
104 */
105 flag(name: string, handler: GlobalFlagHandler, options: Partial<Exclude<CommandFlag, 'name' | 'propertyName'>>): this;
106 /**
107 * Use manifest instance to lazy load commands
108 */
109 useManifest(manifestLoader: ManifestLoader): this;
110 /**
111 * Register an exit handler
112 */
113 onExit(callback: (kernel: this) => void | Promise<void>): this;
114 /**
115 * Returns an array of command names suggestions for a given name.
116 */
117 getSuggestions(name: string, distance?: number): string[];
118 /**
119 * Preload the manifest file. Re-running this method twice will
120 * result in a noop
121 */
122 preloadManifest(): Promise<void>;
123 /**
124 * Finds the command from the command line argv array. If command for
125 * the given name doesn't exists, then it will return `null`.
126 *
127 * Does executes the before and after hooks regardless of whether the
128 * command has been found or not
129 */
130 find(argv: string[]): Promise<CommandConstructorContract | null>;
131 /**
132 * Run the default command. The default command doesn't accept
133 * and args or flags.
134 */
135 runDefaultCommand(): Promise<any>;
136 /**
137 * Execute a command as a sub-command. Do not call "handle" and
138 * always use this method to invoke command programatically
139 */
140 exec(commandName: string, args: string[]): Promise<any>;
141 /**
142 * Makes instance of a given command by processing command line arguments
143 * and setting them on the command instance
144 */
145 handle(argv: string[]): Promise<void>;
146 /**
147 * Print the help screen for a given command or all commands/flags
148 */
149 printHelp(command?: CommandConstructorContract, commandsToAppend?: ManifestCommand[], aliasesToAppend?: Record<string, string>): void;
150 /**
151 * Trigger kernel to exit the process. The call to this method
152 * is ignored when command is not same the `entryCommand`.
153 *
154 * In other words, subcommands cannot trigger exit
155 */
156 exit(command: CommandContract, error?: any): Promise<void>;
157}