Skip to main content

Kernel

The Ace command kernel for AdonisJS applications. This kernel extends the base Ace kernel with AdonisJS-specific functionality like dependency injection and application lifecycle management.

Import

import { Kernel } from '@adonisjs/core/ace'

Constructor

Creates a new Ace kernel instance.
app
ApplicationService
required
The AdonisJS application instance

Example

const app = new Application(new URL('../', import.meta.url))
const kernel = new Kernel(app)

await kernel.handle(['make:controller', 'UserController'])

Properties

app
ApplicationService
Reference to the AdonisJS application instance

Inherited Methods

The Kernel class extends @adonisjs/ace Kernel and inherits all its methods:

handle()

Handle and execute a command with the provided arguments.
argv
string[]
required
Array of command line arguments (e.g., ['make:controller', 'UserController'])
Returns: Promise<any>
await kernel.handle(['make:controller', 'UserController'])

addLoader()

Register a command loader to lazy-load commands.
loader
CommandLoader | (() => Promise<CommandModule>)
required
A loader function or object that provides command metadata and loading logic
Returns: void
kernel.addLoader(() => import('./commands/make_user.js'))

getCommand()

Get a command instance by name.
commandName
string
required
The name of the command to retrieve
Returns: Command | undefined
const command = kernel.getCommand('make:controller')

getMainCommand()

Get the main command that is currently executing. Returns: Command | undefined
const mainCommand = kernel.getMainCommand()

defineFlag()

Define a global flag that is available across all commands.
name
string
required
The name of the flag
options
FlagOptions
required
Configuration options for the flag including type, description, and default value
Returns: void
kernel.defineFlag('verbose', {
  type: 'boolean',
  description: 'Enable verbose output',
  default: false
})

on()

Register an event listener for flag events.
flag
string
required
The flag name to listen for
handler
(command: Command, kernel: Kernel, parsed: ParsedOutput) => any
required
Event handler function
Returns: void
kernel.on('verbose', (command, kernel, parsed) => {
  if (parsed.flags.verbose) {
    kernel.ui.switchMode('verbose')
  }
})

shortcircuit()

Stop command execution and prevent further processing. Returns: symbol
return kernel.shortcircuit()

Factory Function

createAceKernel()

Create and configure an Ace command kernel for AdonisJS applications with default loaders and flags.
import { createAceKernel } from '@adonisjs/core/ace'
app
ApplicationService
required
The AdonisJS application service instance
commandName
string
Optional specific command name for optimized loading
Returns: Kernel

Example

const app = new Application(new URL('../', import.meta.url))
const kernel = createAceKernel(app)

// Run a specific command
await kernel.handle(['make:controller', 'UserController'])

Features

  • Automatically loads commands from rcFile.commands
  • Sets up filesystem loader for application commands
  • Defines global --ansi and --help flags
  • Configures flag listeners for colorful output and help display

See Also