Skip to content

Commit 7703d2e

Browse files
committed
docs: tightly couple e2e-docs tests to literal documentation
1 parent 2aee618 commit 7703d2e

File tree

3 files changed

+630
-678
lines changed

3 files changed

+630
-678
lines changed

docs/features.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ That's it. Easy peasy.
5757
resolved value of other options. Vanilla Yargs does not support these, but Black
5858
Flag does:
5959

60+
<!-- example-region dynamic-options-1 -->
61+
6062
```shell
6163
# These two lines have identical meanings and outputs
6264
myctl 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
7175
myctl init
@@ -92,6 +96,8 @@ existing Yargs ecosystem.
9296
For example, Black Flag helps you validate those [dynamic options][4] using the
9397
same 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
162170
myctl init --lang node --version=23.3
163171
> initializing new node@23.3 project...
164172
```
165173

174+
<!-- example-region all-3 -->
175+
166176
```text
167177
myctl init --lang python --version=23.3
168178
Usage: 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
180192
myctl init --lang fake
181193
Usage: 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
193207
myctl init --help
194208
Usage: myctl init
@@ -208,6 +222,8 @@ function: [`aliases`][6], [`builder`][7], [`command`][8], [`deprecated`][9],
208222
A fully-typed version of `my-cli-project/commands/init.ts` could look something
209223
like 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;
290306
Black Flag not only helps you declaratively build your CLI tool, but _run it_
291307
too.
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
324342
files, followed by [`PreExecutionContext::execute`][19], which is a wrapper
325343
around `yargs::parseAsync` and `yargs::hideBin`.
326344

345+
<!-- example-region run-2 -->
346+
327347
```javascript
328348
const { join } = require('node:path');
329349
const { 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
337359
import { 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
345369
import { join } from 'node:path';
346370
import { configureProgram, isCliError } from '@black-flag/core';
@@ -373,6 +397,8 @@ most bespoke of command line interfaces.
373397
For instance, suppose we added a `my-cli-project/configure.ts` file to our
374398
project:
375399
400+
<!-- example-region convention-1 -->
401+
376402
```typescript
377403
import type {
378404
ConfigureArguments,
@@ -468,6 +494,8 @@ export const configureErrorHandlingEpilogue: ConfigureErrorHandlingEpilogue =
468494
469495
Then 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
813841
who do not prefer TypeScript, you can even type your pure JavaScript files
814842
thanks 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

Comments
 (0)