- Home
- Skills
- Vanman2024
- Cli Builder
- Yargs Patterns
yargs-patterns_skill
- Python
0
GitHub Stars
1
Bundled Files
2 months ago
Catalog Refreshed
4 months ago
First Indexed
Readme & install
Copy the install command, review bundled files from the catalogue, and read any extended description pulled from the listing source.
Installation
Preview and clipboard use veilstrat where the catalogue uses aiagentskills.
npx veilstrat add skill vanman2024/cli-builder --skill yargs-patterns- SKILL.md6.0 KB
Overview
This skill provides advanced yargs patterns and ready-made templates for building professional Node.js CLI tools. It bundles best practices for subcommands, options, middleware, validation, and completion to help teams ship reliable, user-friendly command-line apps. The content focuses on pragmatic examples and reusable templates to speed development and reduce common mistakes.
How this skill works
The skill inspects common CLI requirements and offers concrete yargs recipes: command definitions with positional args, option schemas, middleware hooks, and validation checks. It includes patterns for subcommands with isolated namespaces, conflict/implication rules, array and count options, and shell completion generation. Templates and scripts are provided so you can drop them into a project and customize behavior quickly.
When to use it
- Building a multi-command CLI with subcommands and shared options
- Enforcing input validation and cross-field checks for production tooling
- Composing middleware to load configuration, set logging, or transform args
- Providing shell completions and polished help output for end users
- Creating plugin-capable or extendable CLIs for teams or frameworks
Best practices
- Define clear positional arguments and option types to enable automatic help and coercion
- Use middleware for config loading, environment setup, and verbose logging to keep commands focused
- Validate input with coerce and check to provide early, actionable errors
- Isolate subcommand option namespaces to avoid accidental option collisions
- Use conflicts, implies, and choices to enforce safe option combinations
Example use cases
- Project scaffold CLI with init/build/test subcommands and template selection
- Deployment tool that validates semver versions and enforces environment-specific limits
- Config-driven runner that merges a config file via middleware and supports overrides from CLI
- Tooling wrapper that exposes plugin hooks and completion scripts for Bash/Zsh
- Testing harness that accepts array inputs and count verbosity flags for granular logging
FAQ
Yes. Define middleware on the root yargs instance or export shared middleware functions and apply them where needed to keep behavior consistent.
How do I validate complex cross-field rules?
Use yargs.check to run synchronous or asynchronous validation that inspects multiple argv fields and throws descriptive errors when rules fail.