Installation
# npmnpm install clibuilder
# yarnyarn add clibuilder
# pnpmpnpm add clibuilder
# rushrush add -p clibuilderRequirements
Section titled “Requirements”- Node.js 20.19 or newer.
- TypeScript is optional but recommended. The type inference in
run(args)is the main reason to useclibuilderover a hand-rolled parser; in plain JavaScript everything still works, you just don’t see the inferred types.
Module formats
Section titled “Module formats”clibuilder 11 publishes both ESM and CJS. clibuilder 12 publishes ESM only, and
require('clibuilder') still works through Node’s require(esm), which Node.js 20.19 and newer have
unflagged. Either of these works:
// ESMimport { cli, command, t } from 'clibuilder'// CJSconst { cli, command, t } = require('clibuilder')Arguments and options declare their type with t, which clibuilder
exports. You install nothing for it.
import { t } from 'clibuilder'Optional packages
Section titled “Optional packages”A command’s config takes any Standard Schema. Install the library
you pick as your own dependency, for example npm install zod.
js-yaml is an optional peer dependency. If your users write a .yaml or .yml config file,
install it too:
npm install js-yamlWithout it, reading a YAML config fails with a CliError whose code is missing-peer-dependency.
JSON, JSONC, cjs and mjs config files need nothing extra.
Build something with it: Your First CLI.