commander-js

Provide best practices for building Node.js CLIs with Commander.js.

1|Updated Nov 26, 2014
One-click install
npx skills add https://github.com/tianhuil/dotfiles --skill commander-js
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: commander-js
Source: https://github.com/tianhuil/dotfiles/tree/main/home/.config/opencode/skills/commander-js
Command: npx skills add https://github.com/tianhuil/dotfiles --skill commander-js

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Developers often struggle to architect robust and maintainable CLIs in Node.js. This skill provides non-obvious best practices for designing command-line interfaces with Commander.js, covering structure, reliability, testing, and usability.

Core Features & Use Cases

  • Fluent API usage of the Option class with env bindings and built-in validation.
  • Custom parsers, Infinity sentinel for "no limit" inputs, and robust argument handling.
  • Support for conflicts, implies, and --no- flags to model clear UX in complex CLIs.
  • Testing-friendly patterns: exitOverride, parseAsync, showHelpAfterError, and isolated command definitions.
  • Organized structure: separating definitions from execution and leveraging subcommands with global options.

Quick Start

Create a minimal Commander.js CLI and run it to see basic parsing in action.

Frequently Asked Questions about commander-js

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I build a robust Node.js CLI with Commander.js?

To build a robust Node.js CLI with Commander.js, use the fluent Option class for arguments, separate command definitions from execution, and leverage subcommands with global options for maintainable structure.

What is the best way to test a Commander.js CLI subcommand?

The best way to test a Commander.js CLI is using testing-friendly patterns like exitOverride to prevent process termination, parseAsync for asynchronous operations, and isolated command definitions to evaluate parsing independently.

How do custom parsers handle infinite or no-limit inputs in Commander.js?

Custom parsers in Commander.js handle infinite inputs by using an Infinity sentinel value for no-limit scenarios, ensuring robust argument handling and validation for complex CLI inputs.

Can I model complex CLI UX with conflicts and implied options in Commander.js?

You can model clear CLI UX in Commander.js by defining option conflicts, using implies for dependent flags, and utilizing --no- flags to manage boolean defaults and conflicting states.

Does Commander.js support environment variable bindings for CLI options?

Commander.js supports environment variable bindings through its Option class, allowing you to bind default values directly from environment variables alongside built-in validation rules.

Why should I separate command definitions from execution in Commander.js?

Separating command definitions from execution in Commander.js creates an organized structure, improving reliability and maintainability while making subcommands and global options easier to test independently.