In this directory are a variety of recipes/examples for solving common CLI design problems using Black Flag, Black Flag Extensions, and Black Flag Checks.
Several of these examples are inspired by Yargs's own examples directory.
All examples are easy and simple to run:
- Clone this repository
- Change directory to the example you wish to run
- Run
npm install
(and thennpm run build
for TypeScript-based examples) - Execute
npx cli-name
(replace "cli-name" with the name of the example's CLI)
The only exception is yargs-intro, which consists of a single README.md
file containing code examples instead of an actual runnable program.
- Builder — how to use every available builder
opt
- Deep hierarchy — creating a deep hierarchy of nested commands
- ESM and CJS — mixing different module styles in the same CLI
- Export styles — different syntaxes for exporting commands
- Configuration hooks — fine-tuning the BF runtime
- Shared builder and handler — reusing builders/handlers across commands
- CLI-wide defaults — reconfiguring yargs/yargs-parser across all commands
- Custom context — providing a custom context
- Dynamic options — taking advantage of dynamic options
- Positional — configuring normal and dynamic positionals
- Error handling — handling graceful, CLI, yargs, and custom errors
- Testing — tricks for testing commands, hooks, and CLIs
- TypeScript — building a fully-typed CLI in TypeScript
myctl
re-implementation — upgradingmyctl
from BF to BFE- Builder/handler extensions — how to use every new extended builder
opt
- Usage extensions — how to use usage extensions
- Command passthrough — using one command as an alias for another
- Declarative suboptions — creating powerful dynamic options declaratively
- Declarative checks — taking advantage of declarative per-option checks
- Artificial invocation — running command functions directly (bypass BF)
- Automatic sorting — configuring automatic option sorting (alpha sort)
- Automatic grouping — configuring automatic option grouping