Create a new Kernel instance
The default command to run when no command is specified
The executor for creating and running command instances
The error handler for rendering exceptions
StaticcommandThe default executor for creating command instances and running them
StaticdefaultThe default command to use when creating kernel instance via static create method
OptionalexitThe exit code for the kernel. The exit code is inferred from the main command when not set explicitly
The UI primitives to use within commands
Instance of prompt to display CLI prompts. We share a single instance with all the commands. This allows trapping prompts for commands executed internally
CLI info map containing metadata about the application
List of global flags available across all commands
StaticcreateCreates an instance of kernel with the default executor and default command
Listen for CLI options and execute an action. Only one listener can be defined per option.
The callbacks are only executed for the main command
Define a global flag that is applicable for all commands
The flag name
Flag configuration options
Register a commands loader. The commands will be collected by all loaders.
In case multiple loaders return a single command, the command from the most recent loader will be used.
The loader instance or a function that returns a loader
Check if a command or an alias is registered with kernel
Get the current state of the kernel.
Returns a flat list of commands metadata registered with the kernel. The list is sorted alphabetically by the command name.
Get a list of commands for a specific namespace. All non-namespaces commands will be returned if no namespace is defined.
Optionalnamespace: stringReturns the command metadata by its name. Returns null when the command is missing.
Returns a reference for the default command. The return value is the default command constructor
Returns reference to the main command
Returns an array of aliases registered.
getCommandAliases method to get aliases for a given commandgetAliasCommand to get the command or a given aliasReturns the command metata for a given alias. Returns null if alias is not recognized.
Returns an array of aliases for a given command
Returns a list of namespaces. The list is sorted alphabetically by the namespace name
Returns an array of command and aliases name suggestions for a given keyword.
Returns an array of namespaces suggestions for a given keyword.
Listen for the event before we begin the process of finding the command.
Listen for the event when importing the command
Listen for the event when the command has been imported
Listen for the event before we start to execute the command.
Listen for the event after the command has been executed
Loads commands from all the registered loaders. The "addLoader" method must be called before calling the "load" method.
Find a command by its name
Execute a command. The second argument is an array of command-line arguments (without the command name)
The name of the command to execute
Array of command-line arguments
Creates a command instance by parsing and validating the command-line arguments
The command class to instantiate
Command-line arguments as string or array
A named function that returns true. To be used by flag listeners
The Ace kernel manages the registration and execution of commands.
The kernel is the main entry point of a console application, and is tailored for a standard CLI environment.
Example