PackagesCerebroIntroduction

Introduction

Cerebro is a modern, TypeScript-first CLI framework for building powerful command-line applications.

Last updated:

Cerebro is a modern, TypeScript-first CLI framework that makes it easy to build powerful command-line applications. Built with performance and developer experience in mind, Cerebro provides everything you need to create awesome CLIs.

Cerebro Output

Why Cerebro?

Fast & Lightweight

Cerebro is optimized for performance with minimal overhead. Your CLI starts quickly and runs efficiently, even with complex command structures.

TypeScript First

Full TypeScript support with excellent type inference. Get autocomplete, type safety, and better developer experience out of the box.

Extensible

Plugin system allows you to extend functionality without modifying core code. Add features like logging, prompts, file system operations, and more.

Feature Rich

Built-in support for:

  • Commands with arguments and options
  • Shell autocompletions (bash, zsh, fish, powershell)
  • Help generation
  • README documentation generation
  • Error handling
  • Plugin lifecycle hooks
  • Command composition

Zero Configuration

Get started in minutes. Sensible defaults mean you can build a working CLI without any configuration.

Quick Navigation

Key Features

Commands

Define commands with descriptions, options, arguments, and aliases. Commands can be grouped, hidden, or configured with examples.

cli.addCommand({
    name: "build",
    description: "Build your project",
    options: [
        { name: "production", type: Boolean },
        { name: "output", type: String },
    ],
    execute: ({ options, logger }) => {
        logger.info(`Building ${options.production ? "production" : "development"}...`);
    },
});

Options

Powerful option handling with support for:

  • Type validation (String, Number, Boolean, Arrays)
  • Default values
  • Required options
  • Aliases
  • Negatable options (--no- prefix)
  • Conflicting options
  • Implied options

Arguments

Positional arguments with type checking and default values.

cli.addCommand({
    name: "greet",
    argument: {
        name: "name",
        type: String,
        description: "Name to greet",
    },
    execute: ({ argument }) => {
        console.log(`Hello, ${argument[0]}!`);
    },
});

Plugins

Extend functionality with plugins that hook into the command lifecycle:

  • init - Called once during plugin initialization
  • execute - Called during command execution (extends toolbox)
  • beforeCommand - Called before command execution
  • afterCommand - Called after successful command execution
  • onError - Called when errors occur

Command Composition

Call commands from within other commands using runtime.runCommand():

cli.addCommand({
    name: "deploy",
    execute: async ({ runtime, logger }) => {
        logger.info("Building...");
        await runtime.runCommand("build", { argv: ["--production"] });

        logger.info("Testing...");
        await runtime.runCommand("test");

        logger.info("Deploying...");
    },
});

Installation

bash pnpm add @visulima/cerebro
bash npm install @visulima/cerebro
bash yarn add @visulima/cerebro

Next Steps

Ready to build your CLI? Head to the Quick Start guide to create your first command in minutes!

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