Building a CLI Tool in Node.js That People Actually Want to Use
What Makes a Good CLI? Most developer tools are CLIs. git, docker, npm, gh—all of them. A well-built CLI is invisible: it does what you expect, fails clearly, and stays out of the way. Here's how t...

Source: DEV Community
What Makes a Good CLI? Most developer tools are CLIs. git, docker, npm, gh—all of them. A well-built CLI is invisible: it does what you expect, fails clearly, and stays out of the way. Here's how to build one that meets that bar. Setup with TypeScript mkdir my-cli && cd my-cli npm init -y npm install commander chalk ora execa npm install -D typescript @types/node ts-node tsup // package.json additions { "bin": { "mycli": "./dist/index.js" }, "scripts": { "build": "tsup src/index.ts --format cjs --dts", "dev": "ts-node src/index.ts" } } Commander: Argument Parsing #!/usr/bin/env node import { Command } from 'commander'; import { deploy } from './commands/deploy'; import { init } from './commands/init'; const program = new Command(); program .name('mycli') .description('Deploy and manage your applications') .version('1.0.0'); program .command('init') .description('Initialize a new project') .option('-t, --template <template>', 'project template', 'default') .option('--no-gi