Back to Skills

yargs-patterns

verified

Advanced yargs patterns for Node.js CLI argument parsing with subcommands, options, middleware, and validation

View on GitHub

Marketplace

cli-builder

vanman2024/cli-builder

Plugin

cli-builder

development

Repository

vanman2024/cli-builder

plugins/cli-builder/skills/yargs-patterns/SKILL.md

Last Verified

January 22, 2026

Install Skill

Select agents to install to:

Scope:
npx add-skill https://github.com/vanman2024/cli-builder/blob/main/plugins/cli-builder/skills/yargs-patterns/SKILL.md -a claude-code --skill yargs-patterns

Installation paths:

Claude
.claude/skills/yargs-patterns/
Powered by add-skill CLI

Instructions

# yargs Patterns Skill

Comprehensive patterns and templates for building CLI applications with yargs, the modern Node.js argument parsing library.

## Overview

yargs is a powerful argument parsing library for Node.js that provides:
- Automatic help generation
- Rich command syntax (positional args, options, flags)
- Type coercion and validation
- Subcommands with isolated option namespaces
- Middleware for preprocessing
- Completion scripts for bash/zsh

## Quick Reference

### Basic Setup

```javascript
#!/usr/bin/env node
const yargs = require('yargs/yargs');
const { hideBin } = require('yargs/helpers');

yargs(hideBin(process.argv))
  .command('* <name>', 'greet someone', (yargs) => {
    yargs.positional('name', {
      describe: 'Name to greet',
      type: 'string'
    });
  }, (argv) => {
    console.log(`Hello, ${argv.name}!`);
  })
  .parse();
```

### Subcommands

```javascript
yargs(hideBin(process.argv))
  .command('init <project>', 'initialize a new project', (yargs) => {
    yargs
      .positional('project', {
        describe: 'Project name',
        type: 'string'
      })
      .option('template', {
        alias: 't',
        describe: 'Project template',
        choices: ['basic', 'advanced', 'minimal'],
        default: 'basic'
      });
  }, (argv) => {
    console.log(`Initializing ${argv.project} with ${argv.template} template`);
  })
  .command('build [entry]', 'build the project', (yargs) => {
    yargs
      .positional('entry', {
        describe: 'Entry point file',
        type: 'string',
        default: 'index.js'
      })
      .option('output', {
        alias: 'o',
        describe: 'Output directory',
        type: 'string',
        default: 'dist'
      })
      .option('minify', {
        describe: 'Minify output',
        type: 'boolean',
        default: false
      });
  }, (argv) => {
    console.log(`Building from ${argv.entry} to ${argv.output}`);
  })
  .parse();
```

### Options and Flags

```javascript
yargs(hideBin(p

Validation Details

Front Matter
Required Fields
Valid Name Format
Valid Description
Has Sections
Allowed Tools
Instruction Length:
5183 chars