@@ -57,6 +57,8 @@ That's it. Easy peasy.
5757resolved value of other options. Vanilla Yargs does not support these, but Black
5858Flag does:
5959
60+ <!-- example-region dynamic-options-1 -->
61+
6062``` shell
6163# These two lines have identical meanings and outputs
6264myctl init --lang node
@@ -66,6 +68,8 @@ myctl init --lang node --version=23.3
6668> initializing new node@23.3 project...
6769```
6870
71+ <!-- example-region dynamic-options-2 -->
72+
6973``` shell
7074# And these three lines have identical meanings and outputs
7175myctl init
@@ -92,6 +96,8 @@ existing Yargs ecosystem.
9296For example, Black Flag helps you validate those [ dynamic options] [ 4 ] using the
9397same Yargs API you already know and love:
9498
99+ <!-- example-region all-1 -->
100+
95101``` typescript
96102// File: my-cli-project/commands/init.ts
97103
@@ -158,11 +164,15 @@ export function handler(argv) {
158164
159165> See [ the demo repo] [ 5 ] for the complete implementation of this command.
160166
167+ <!-- example-region all-2 -->
168+
161169``` text
162170myctl init --lang node --version=23.3
163171> initializing new node@23.3 project...
164172```
165173
174+ <!-- example-region all-3 -->
175+
166176``` text
167177myctl init --lang python --version=23.3
168178Usage: myctl init
@@ -176,6 +186,8 @@ Invalid values:
176186 Argument: version, Given: "23.3", Choices: "3.11", "3.12", "3.13"
177187```
178188
189+ <!-- example-region all-4 -->
190+
179191``` text
180192myctl init --lang fake
181193Usage: myctl init
@@ -189,6 +201,8 @@ Invalid values:
189201 Argument: lang, Given: "fake", Choices: "node", "python"
190202```
191203
204+ <!-- example-region all-5 -->
205+
192206``` text
193207myctl init --help
194208Usage: myctl init
@@ -208,6 +222,8 @@ function: [`aliases`][6], [`builder`][7], [`command`][8], [`deprecated`][9],
208222A fully-typed version of ` my-cli-project/commands/init.ts ` could look something
209223like this:
210224
225+ <!-- example-region all-6 -->
226+
211227``` typescript
212228// File: my-cli-project/commands/init.ts
213229
@@ -290,6 +306,8 @@ export default configuration;
290306Black Flag not only helps you declaratively build your CLI tool, but _ run it_
291307too.
292308
309+ <!-- example-region run-1 -->
310+
293311``` typescript
294312#! / usr / bin / env node
295313// File: my-cli-project/cli.ts
@@ -324,6 +342,8 @@ auto-discovers and collects all the configurations exported from your command
324342files, followed by [ ` PreExecutionContext::execute ` ] [ 19 ] , which is a wrapper
325343around ` yargs::parseAsync ` and ` yargs::hideBin ` .
326344
345+ <!-- example-region run-2 -->
346+
327347``` javascript
328348const { join } = require (' node:path' );
329349const { runProgram } = require (' @black-flag/core' );
@@ -333,6 +353,8 @@ module.exports = runProgram(join(__dirname, 'commands'));
333353
334354👆🏿 These are essentially equivalent 👇🏿
335355
356+ <!-- example-region run-3 -->
357+
336358``` javascript
337359import { runProgram } from ' @black-flag/core' ;
338360
@@ -341,6 +363,8 @@ export default runProgram(import.meta.resolve('./commands'));
341363
342364👆🏿 These are essentially equivalent 👇🏿
343365
366+ <!-- example-region run-4 -->
367+
344368` ` ` javascript
345369import { join } from ' node:path' ;
346370import { configureProgram , isCliError } from ' @black-flag/core' ;
@@ -373,6 +397,8 @@ most bespoke of command line interfaces.
373397For instance, suppose we added a ` my- cli- project/ configure .ts ` file to our
374398project:
375399
400+ <!-- example-region convention-1 -->
401+
376402` ` ` typescript
377403import type {
378404 ConfigureArguments ,
@@ -468,6 +494,8 @@ export const configureErrorHandlingEpilogue: ConfigureErrorHandlingEpilogue =
468494
469495Then our CLI's entry point might look something like this:
470496
497+ <!-- example-region convention-2 -->
498+
471499` ` ` typescript
472500#! / usr/ bin/ env node
473501// File: my-cli-project/cli.ts
@@ -813,6 +841,8 @@ enjoy the improved DX that comes with comprehensive intellisense. And for those
813841who do not prefer TypeScript, you can even type your pure JavaScript files
814842thanks to JSDoc syntax. No TypeScript required!
815843
844+ <!-- example-region intellisense-1 -->
845+
816846```javascript
817847// @ts-check
818848// This is a pure CJS JavaScript file, no TypeScript allowed!
0 commit comments