CerebroAPI ReferenceAPI Overview

API Overview

Last updated:

API Overview

Complete API reference for Cerebro CLI framework.

Core API

createCerebro()

Create a new CLI instance:

function createCerebro<T extends Console = Console>(name: string, options?: CliOptions<T>): Cerebro<T>;

Parameters:

  • name - CLI application name
  • options - Configuration options (optional)

Returns: Configured Cerebro instance

Example:

const cli = createCerebro("my-cli", {
    packageName: "my-cli",
    packageVersion: "1.0.0",
});

Cerebro Class

Main CLI class with the following methods:

addCommand()

Register a command:

cli.addCommand(command: Command): void

use()

Register a plugin:

cli.use(plugin: Plugin): void

run()

Execute the CLI:

await cli.run(argv?: string[]): Promise<void>

setDefaultCommand()

Set default command:

cli.setDefaultCommand(name: string): void

getCommands()

Get all registered commands:

cli.getCommands(): Map<string, Command>

Built-in Commands

  • HelpCommand - Display help text
  • VersionCommand - Show version
  • CompletionCommand - Shell completion
  • ReadmeCommand - Generate README

Built-in Plugins

  • errorHandlerPlugin - Error handling
  • runtimeVersionCheckPlugin - Version validation
  • updateNotifierPlugin - Update notifications

Type Definitions

  • Command - Command definition interface (supports execute or loader)
  • CommandExecute - Handler signature shared by execute and loader
  • LazyCommandModule - Module shape returned by a command loader
  • Plugin - Plugin definition interface
  • Toolbox - Execution context interface
  • CliOptions - CLI configuration options
  • OptionDefinition - Option definition interface
  • ArgumentDefinition - Argument definition interface
  • EnvDefinition - Environment variable definition
  • CreateOptions - Derive a typed options object from a kebab-case input
  • CreateEnv - Derive a typed env object from an UPPER_SNAKE_CASE input
  • OptionNameToCamelCase - String type that converts output-diroutputDir

Helpers

  • lazyNamed(load, key) - Builds a loader for handlers exported as named entries from a shared module
  • createCerebro(name, options) - Factory function for a Cerebro instance

Errors

  • CerebroError - Base error class
  • CommandNotFoundError - Command lookup failed
  • CommandValidationError - Command failed validation (e.g. missing required option)
  • CommandLoaderError - loader rejected or returned no default-exported function
  • ConflictingOptionsError - Two options that conflict were both passed
  • PluginError - A plugin threw during a lifecycle hook

Constants

  • VERBOSITY_QUIET - Quiet output level
  • VERBOSITY_NORMAL - Normal output level
  • VERBOSITY_VERBOSE - Verbose output level
  • VERBOSITY_DEBUG - Debug output level
Support

Contribute to our work and keep us going

Community is the heart of open source. The success of our packages wouldn't be possible without the incredible contributions of users, testers, and developers who collaborate with us every day.Want to get involved? Here are some tips on how you can make a meaningful impact on our open source projects.

Ready to help us out?

Be sure to check out the package's contribution guidelines first. They'll walk you through the process on how to properly submit an issue or pull request to our repositories.

Submit a pull request

Found something to improve? Fork the repo, make your changes, and open a PR. We review every contribution and provide feedback to help you get merged.

Good first issues

Simple issues suited for people new to open source development, and often a good place to start working on a package.
View good first issues