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 nameoptions- 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): voiduse()
Register a plugin:
cli.use(plugin: Plugin): voidrun()
Execute the CLI:
await cli.run(argv?: string[]): Promise<void>setDefaultCommand()
Set default command:
cli.setDefaultCommand(name: string): voidgetCommands()
Get all registered commands:
cli.getCommands(): Map<string, Command>Built-in Commands
HelpCommand- Display help textVersionCommand- Show versionCompletionCommand- Shell completionReadmeCommand- Generate README
Built-in Plugins
errorHandlerPlugin- Error handlingruntimeVersionCheckPlugin- Version validationupdateNotifierPlugin- Update notifications
Type Definitions
Command- Command definition interface (supportsexecuteorloader)CommandExecute- Handler signature shared byexecuteandloaderLazyCommandModule- Module shape returned by a commandloaderPlugin- Plugin definition interfaceToolbox- Execution context interfaceCliOptions- CLI configuration optionsOptionDefinition- Option definition interfaceArgumentDefinition- Argument definition interfaceEnvDefinition- Environment variable definitionCreateOptions- Derive a typed options object from a kebab-case inputCreateEnv- Derive a typed env object from an UPPER_SNAKE_CASE inputOptionNameToCamelCase- String type that convertsoutput-dir→outputDir
Helpers
lazyNamed(load, key)- Builds aloaderfor handlers exported as named entries from a shared modulecreateCerebro(name, options)- Factory function for aCerebroinstance
Errors
CerebroError- Base error classCommandNotFoundError- Command lookup failedCommandValidationError- Command failed validation (e.g. missing required option)CommandLoaderError-loaderrejected or returned no default-exported functionConflictingOptionsError- Two options that conflict were both passedPluginError- A plugin threw during a lifecycle hook
Constants
VERBOSITY_QUIET- Quiet output levelVERBOSITY_NORMAL- Normal output levelVERBOSITY_VERBOSE- Verbose output levelVERBOSITY_DEBUG- Debug output level