Skip to content

Commit b6da858

Browse files
committed
docs: add strictFlags documentation to README
1 parent 98cdbff commit b6da858

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

README.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,35 @@ $ my-script --version
335335

336336
The version is also shown in the help documentation. To opt out of handling `--version` while still showing the version in `--help`, pass the version into `help.version`.
337337

338+
#### Strict flags
339+
To reject unknown flags with an error, enable `strictFlags`:
340+
341+
```ts
342+
cli({
343+
flags: {
344+
foo: Boolean,
345+
bar: String
346+
},
347+
strictFlags: true
348+
})
349+
```
350+
351+
```sh
352+
$ my-script --baz
353+
Error: Unknown flag: --baz. (Did you mean --bar?)
354+
```
355+
356+
When enabled, the CLI will exit with an error if any unknown flags are passed. If a similar flag name exists (within 2 edits), it will suggest the closest match.
357+
358+
Commands inherit `strictFlags` from the parent CLI, but can override it:
359+
360+
```ts
361+
command({
362+
name: 'build',
363+
strictFlags: false // Disable for this command
364+
})
365+
```
366+
338367
### Commands
339368
Commands allow organizing multiple "scripts" into a single script. An example of this is the [`npm install`](https://docs.npmjs.com/cli/install/) command, which is essentially an "install" script inside the "npm" script, adjacent to other commands like [`npm run`](https://docs.npmjs.com/cli/run-script/).
340369

0 commit comments

Comments
 (0)