Clap.js is a robust library for Node.js designed to simplify the creation of command-line interfaces (CLIs). It provides a fluent API for defining commands, options, and arguments, supporting advanced features like argument coercion, completion suggestions, and sub-commands. The library aims to facilitate both simple CLI tools and complex applications with deep command hierarchies. Inspired by Commander.js, Clap.js focuses on ease of use and flexibility. The current stable version is 3.1.1, with recent releases addressing regressions and refining API signatures. Since version 3.0.0, it supports both ESM and CommonJS (dual module) and targets Node.js versions `^12.20.0`, `^14.13.0`, and `>=15.0.0`. It offers a structured approach to argv processing and context management for developers building intricate command-line tools.
npm install clapVerified import paths — ran on the pinned version, not inferred.
Demonstrates basic CLI setup with options, arguments, version, description, sub-commands, and an action function to process parsed values.
Ensure your project is configured for ESM (e.g., `"type": "module"` in package.json) or use appropriate CommonJS imports. Update Node.js to a supported version.
Refactor `command()` calls to only pass the usage string as the first parameter (e.g., `command('my-command [arg1]')`). Ensure no additional parameters are provided.Upgrade Node.js to version 8 or higher. If migrating from v1, review method names like `create()` which are no longer part of the public API in current versions.
Consult the `.option()` API documentation carefully for the correct usage patterns and argument definitions, particularly for `normalize` and `default` values.
Ensure the `command()` method receives only one string parameter, representing the command's usage (e.g., `command('my-command [arg]')`).Migrate your import statements to ESM `import { command } from 'clap';` or `import cli from 'clap';`.For ESM, use `import { command } from 'clap';` if `command` is a named export, or `import cli from 'clap';` then access via `cli.command(...)` if it's a method on the default export.No dependency data recorded yet.