Skip to content

Commit

Permalink
Update README to reflect strict:true behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronccasanova committed Apr 12, 2022
1 parent e66a8b3 commit a4fc92a
Showing 1 changed file with 16 additions and 14 deletions.
30 changes: 16 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ process.mainArgs = process.argv.slice(process._exec ? 1 : 2)
* `type` {'string'|'boolean'} (Required) Type of known option
* `multiple` {boolean} (Optional) If true, when appearing one or more times in `args`, results are collected in an `Array`
* `short` {string} (Optional) A single character alias for an option; When appearing one or more times in `args`; Respects the `multiple` configuration
* `strict` {Boolean} (Optional) A `Boolean` on wheather or not to throw an error when unknown args are encountered
* `strict` {Boolean} (Optional) A `Boolean` for whether or not to throw an error when unknown options are encountered, `type:'string'` options are missing an options-argument, or `type:'boolean'` options are passed an options-argument; defaults to `true`
* Returns: {Object} An object having properties:
* `values` {Object}, key:value for each option found. Value is a string for string options, or `true` for boolean options, or an array (of strings or booleans) for options configured as `multiple:true`.
* `positionals` {string[]}, containing [Positionals][]
Expand All @@ -97,24 +97,14 @@ process.mainArgs = process.argv.slice(process._exec ? 1 : 2)
const { parseArgs } = require('@pkgjs/parseargs');
```
```js
// unconfigured
const { parseArgs } = require('@pkgjs/parseargs');
const args = ['-f', '--foo=a', '--bar', 'b'];
const options = {};
const { values, positionals } = parseArgs({ args, options });
// values = { f: true, foo: 'a', bar: true }
// positionals = ['b']
```
```js
const { parseArgs } = require('@pkgjs/parseargs');
// type:string
const args = ['-f', '--foo=a', '--bar', 'b'];
const options = {
bar: {
type: 'string',
},
f: { type: 'boolean' },
foo: { type: 'string'},
bar: { type: 'string' },
};
const { values, positionals } = parseArgs({ args, options });
// values = { f: true, foo: 'a', bar: 'b' }
Expand All @@ -126,6 +116,7 @@ const { parseArgs } = require('@pkgjs/parseargs');
// type:string & multiple
const args = ['-f', '--foo=a', '--foo', 'b'];
const options = {
f: { type: 'boolean' },
foo: {
type: 'string',
multiple: true,
Expand All @@ -151,6 +142,17 @@ const { values, positionals } = parseArgs({ args, options });
// positionals = ['b']
```
```js
// unconfigured
const { parseArgs } = require('@pkgjs/parseargs');
const args = ['-f', '--foo=a', '--bar', 'b'];
const options = {};
const { values, positionals } = parseArgs({ strict: false, args, options });
// values = { f: true, foo: 'a', bar: true }
// positionals = ['b']
```
### F.A.Qs
- Is `cmd --foo=bar baz` the same as `cmd baz --foo=bar`?
Expand Down

0 comments on commit a4fc92a

Please sign in to comment.