Skip to content

Commit c30dbfd

Browse files
committed
add options.unknown docs & diffs to readme
1 parent 3664558 commit c30dbfd

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

readme.md

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,17 @@ Default: `[]`
9393

9494
A single key (or array of keys) that should be parsed as `String`s.
9595

96+
#### options.unknown
97+
98+
Type: `function`<br>
99+
Default: `undefined`
100+
101+
Callback that is run when a parsed flag has not been defined as a known key or alias. Its only parameter is the unknown flag itself; eg `--foobar` or `-f`.
102+
103+
Once an unknown flag is encountered, parsing will terminate, regardless of your return value.
104+
105+
> **Note:** `mri` _only_ checks for unknown flags if `options.unknown` **and** `options.alias` are populated. Otherwise, everything will be accepted.
106+
96107

97108
## Comparisons
98109

@@ -109,9 +120,10 @@ A single key (or array of keys) that should be parsed as `String`s.
109120
mri(['-abc', 'hello']);
110121
//=> { _:[], a:true, b:true, c:'hello' }
111122
```
123+
- The `opts.unknown` behaves differently:
124+
- Unlike `minimist`, `mri` will not continue continue parsing after encountering an unknown flag
112125
- Missing `options`:
113126
- `opts.stopEarly`
114-
- `opts.unknown`
115127
- `opts['--']`
116128
- Ignores newlines (`\n`) within args (see [test](https://github.com/substack/minimist/blob/master/test/parse.js#L69-L80))
117129
- Ignores slashBreaks within args (see [test](https://github.com/substack/minimist/blob/master/test/parse.js#L147-L157))
@@ -135,6 +147,7 @@ A single key (or array of keys) that should be parsed as `String`s.
135147
- `opts['--']`
136148
- Missing [`parser.detailed()`](https://github.com/yargs/yargs-parser#requireyargs-parserdetailedargs-opts) method
137149
- No [additional configuration](https://github.com/yargs/yargs-parser#configuration) object
150+
- Added [`options.unknown`](##optionsunknown) feature
138151

139152

140153
## Benchmarks

0 commit comments

Comments
 (0)