Skip to content
OpenSmartRoute
Skillv1.0.0

commander

Build CLI tools with Commander.js. Use when creating command-line applications, parsing arguments, implementing subcommands, or building developer tools with flags and options.

by terminalskills(0) 0 installs
Free
Sign in to install

Free account. Installing gives you the manifest plus copy-paste snippets.

See reviews

About

Imported from terminalskills/skills (skills/commander/SKILL.md). Install upstream with npx skills add terminalskills/skills --skill commander. Copyright stays with the author (Apache-2.0).

Commander.js

Overview

Commander is the standard library for building Node.js CLIs. Parse arguments, define subcommands, generate help text, and handle options. Powers thousands of CLIs including create-react-app, eslint, and prisma.

Instructions

Step 1: Basic CLI

// cli.ts — CLI with commands and options
import { Command } from 'commander'

const program = new Command()
  .name('mytools')
  .description('Developer productivity toolkit')
  .version('1.0.0')

program
  .command('init')
  .description('Initialize a new project')
  .argument('<name>', 'project name')
  .option('-t, --template <type>', 'project template', 'default')
  .option('--no-git', 'skip git initialization')
  .option('-d, --dry-run', 'show what would be created')
  .action(async (name, opts) => {
    console.log(`Creating project: ${name}`)
    console.log(`Template: ${opts.template}`)
    if (opts.dryRun) { console.log('(dry run)'); return }
    await createProject(name, opts)
  })

program
  .command('deploy')
  .description('Deploy to production')
  .option('-e, --env <environment>', 'target environment', 'production')
  .option('--force', 'skip confirmation')
  .action(async (opts) => {
    if (!opts.force) {
      const ok = await confirm(`Deploy to ${opts.env}?`)
      if (!ok) process.exit(0)
    }
    await deploy(opts.env)
  })

program.parse()

Step 2: Package Setup

{
  "name": "mytools",
  "bin": { "mytools": "./dist/cli.js" },
  "scripts": {
    "build": "tsc",
    "dev": "tsx src/cli.ts"
  }
}
# Development
npx tsx src/cli.ts init my-project --template react

# After build + npm link
mytools init my-project --template react
mytools deploy --env staging
mytools --help

Guidelines

  • Commander auto-generates --help from your command definitions.
  • Use argument() for required positional args, option() for flags.
  • --no-* flags automatically create boolean negations (e.g., --no-gitopts.git === false).
  • Exit codes: 0 for success, 1 for errors. Commander handles parse errors automatically.
  • For interactive prompts, pair with Inquirer or @clack/prompts.

Use it

Copy one of these into your project. Installing also returns the manifest and these snippets.

yaml
targets:
  - https://api.opensmartroute.ai/api/v1/registry/terminalskills-skills-commander/manifest   # or paste the manifest below

Manifest

An Open Capability Manifest: the router reads it to know what this does, what it costs and when to pick it.

terminalskills-skills-commander.ocm.jsonjson
{
  "ocm": "1",
  "id": "terminalskills-skills-commander",
  "kind": "skill",
  "name": "commander",
  "description": "Build CLI tools with Commander.js. Use when creating command-line applications, parsing arguments, implementing subcommands, or building developer tools with flags and options.",
  "publisher": "terminalskills",
  "version": "1.0.0",
  "capabilities": {
    "domains": [
      "general"
    ],
    "tags": [
      "skill-md",
      "commander",
      "cli",
      "nodejs",
      "developer-tools",
      "terminal",
      "skills-sh"
    ],
    "languages": [
      "en"
    ]
  },
  "quality_prior": 0.6,
  "examples": [
    "Build CLI tools with Commander.js. Use when creating command-line applications, parsing arguments, implementing subcommands, or building developer tools with flags and options."
  ],
  "primary": false,
  "metadata": {
    "source": {
      "provider": "skills.sh",
      "repository": "https://github.com/terminalskills/skills",
      "path": "skills/commander/SKILL.md",
      "ref": "HEAD",
      "url": "https://github.com/terminalskills/skills/blob/HEAD/skills/commander/SKILL.md",
      "key": "terminalskills/skills/skills/commander/SKILL.md"
    },
    "compatibility": "Node.js 14+",
    "license": "Apache-2.0"
  },
  "instructions": "# Commander.js\n\n## Overview\n\nCommander is the standard library for building Node.js CLIs. Parse arguments, define subcommands, generate help text, and handle options. Powers thousands of CLIs including create-react-app, eslint, and prisma.\n\n## Instructions\n\n### Step 1: Basic CLI\n\n```typescript\n// cli.ts — CLI with commands and options\nimport { Command } from 'commander'\n\nconst program = new Command()\n  .name('mytools')\n  .description('Developer productivity toolkit')\n  .version('1.0.0')\n\nprogram\n  .command('init')\n  .description('Initialize a new project')\n  .argument('<name>', 'project name')",
  "cost": {
    "context_tokens": 537
  }
}

Fetch it by URL: GET /api/v1/registry/terminalskills-skills-commander/manifest?version=1.0.0

Reviews

Star ratings from people who tried it. One review per account; edit yours any time.

No reviews yet. Install it, try it, and be the first to rate it.

commander - Skill - OpenSmartRoute