cli
raw JSON → 1.0.1 verified Sat Apr 25 auth: no javascript maintenance
A full-featured command-line application toolkit for Node.js (v1.0.1, latest, infrequently updated). Provides argument parsing, plugin support, colored output, progress bars, spinners, auto-completion, and stdin helpers. Differentiates from yargs and commander by its inclusive feature set and mature legacy API.
Common errors
error TypeError: cli.withStdin is not a function ↓
cause Attempting to call withStdin without requiring cli correctly.
fix
const cli = require('cli'); then cli.withStdin(...)
error Error: Cannot find module 'cli' ↓
cause Missing npm install or incorrect require path.
fix
Run 'npm install cli' and ensure it is in node_modules.
error ReferenceError: cli is not defined ↓
cause Trying to use cli without requiring it.
fix
Add 'const cli = require('cli');' at the top.
Warnings
gotcha The package is old and uses CommonJS only; there is no ESM version. ↓
fix Use require('cli') instead of import.
gotcha The default export is a function; calling require('cli')() is incorrect. ↓
fix Assign to a variable and use its methods.
deprecated The package is not actively maintained; newer alternatives like yargs or commander exist. ↓
fix Consider migrating to a maintained library.
gotcha Auto-completion feature may not work in all environments. ↓
fix Test on target shells.
Install
npm install cli yarn add cli pnpm add cli Imports
- cli
const cli = require('cli') - cli.parse wrong
const { parse } = require('cli'); parse(options)correctcli.parse(options) - cli.withStdin wrong
withStdin(callback)correctcli.withStdin(callback)
Quickstart
const cli = require('cli');
cli.parse({
file: ['f', 'A file to process', 'file', 'temp.log'],
time: ['t', 'An access time', 'time', false],
work: [false, 'What kind of work to do', 'string', 'sleep']
});
cli.withStdinLines((lines, newline) => {
if (cli.options.file) {
cli.output(`File option: ${cli.options.file}`);
}
cli.output(lines.join(newline));
});