Commandpost is a command-line option parser library for Node.js, designed with a strong emphasis on TypeScript developer experience while remaining fully compatible with JavaScript projects. It provides a structured, chainable API for defining root commands, sub-commands, various types of options (e.g., flags, parameters), and arguments (required, optional, variadic). Inspired by the popular `commander` library, Commandpost differentiates itself by addressing `commander`'s limitations regarding robust TypeScript type inference and usage, offering a more type-safe approach to CLI development. The current stable version is 1.4.0, with releases historically following an irregular cadence based on community contributions and author availability, rather than fixed schedules. Key features include automatic help message generation, versioning, and descriptive capabilities for commands and options. Its core strength lies in enabling developers to build type-safe CLI applications with a familiar, fluid API.
npm install commandpostVerified import paths — ran on the pinned version, not inferred.
Sets up a basic CLI command `dinner <food>` with an optional `--spice` flag. This example demonstrates defining commands, parsing options and arguments, and handling execution errors.
When expecting a single string value for an option, access the first element in your action handler (e.g., `opts.spice[0]`). For options without parameters (flags), the value converts to `boolean`.
Refer to the `commandpost` documentation and examples, particularly the `example/usage.ts` file on GitHub, to understand its specific API patterns and TypeScript type definitions.
Always chain a `.catch()` block to `commandpost.exec()` to provide user-friendly error messages and ensure the process exits with an appropriate error code.
Define the option using `.option('-f, --foo', 'Description')` on your command, or explicitly allow unknown options by calling `.allowUnknownOption()` on the command definition.Ensure all required arguments are provided on the command line when executing. For example, if `<food>` is required, invoke as `cli.js <food_value>`.
For TypeScript and ESM, use `import * as commandpost from 'commandpost';`. If strictly using CommonJS, ensure `const commandpost = require('commandpost');` is used, and functions are called as `commandpost.create()`.No dependency data recorded yet.