CAC (Command And Conquer) is a lightweight, dependency-free JavaScript library for building robust command-line interface (CLI) applications. The current stable version, 7.0.0, released in 2024, marks a significant transition to being ESM-only and requires Node.js 20.19.0 or newer. CAC differentiates itself by providing a minimal API surface (four core methods for basic CLIs) while offering powerful features such as default commands, Git-like subcommands, argument and option validation, variadic arguments, and automated help message generation. Its development is TypeScript-first, ensuring type safety and an enhanced developer experience. Release cadence is typically feature-driven, with breaking changes carefully documented in major version bumps and minor/patch releases focusing on stability and compatibility.
npm install cacVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to initialize CAC, define options and commands, set a version, and enable automatic help message generation. It includes a basic error handling block for parsing issues.
Upgrade your Node.js environment to version 20.19.0 or higher. Use a version manager like `nvm` to easily switch Node.js versions (e.g., `nvm install 20 && nvm use 20`).
Migrate your project to use ES module `import` syntax (e.g., `import cac from 'cac'`). Ensure your `package.json` specifies `"type": "module"` or use `.mjs` file extensions. For mixed environments, consider dynamic `import()` or transpilation.
Update all calls to these event methods in your codebase to use the new `addEventListener`-like naming conventions.
When defining options with kebab-case, always access them in your action functions using their camelCase equivalent.
Always define an `.action()` for commands that have options if you require strict validation. If intentionally allowing unknown options, use `command.allowUnknownOptions()`.
Convert your script to an ES module by using `import cac from 'cac'` and ensuring your project's `package.json` has `"type": "module"` or your file has a `.mjs` extension.
Rename `cli.on()` to `cli.addEventListener()` everywhere in your code. Similarly, replace `cli.once()` with `cli.addOnceListener()` and `cli.off()` with `cli.removeEventListener()`.
Update your Node.js environment to version 20.19.0 or higher. You can use tools like `nvm use 20` or `volta install node@20`.
No dependency data recorded yet.