meow
Advanced tools
Comparing version 7.1.1 to 8.0.0
@@ -29,3 +29,3 @@ import {PackageJson} from 'type-fest'; | ||
type AnyFlag = StringFlag | BooleanFlag | NumberFlag; | ||
type AnyFlags = {[key: string]: AnyFlag}; | ||
type AnyFlags = Record<string, AnyFlag>; | ||
@@ -44,2 +44,3 @@ interface Options<Flags extends AnyFlags> { | ||
- `isMultiple`: Indicates a flag can be set multiple times. Values are turned into an array. (Default: false) | ||
Multiple values are provided by specifying the flag multiple times, for example, `$ foo -u rainbow -u cat`. Space- or comma-separated values are *not* supported. | ||
@@ -111,3 +112,3 @@ @example | ||
*/ | ||
readonly pkg?: {[key: string]: unknown}; | ||
readonly pkg?: Record<string, unknown>; | ||
@@ -131,6 +132,10 @@ /** | ||
/** | ||
Value of `boolean` flags not defined in `argv`. If set to `undefined` the flags not defined in `argv` will be excluded from the result. The `default` value set in `boolean` flags take precedence over `booleanDefault`. | ||
Value of `boolean` flags not defined in `argv`. | ||
__Caution: Explicitly specifying undefined for `booleanDefault` has different meaning from omitting key itself.__ | ||
If set to `undefined`, the flags not defined in `argv` will be excluded from the result. The `default` value set in `boolean` flags take precedence over `booleanDefault`. | ||
_Note: If used in conjunction with `isMultiple`, the default flag value is set to `[]`._ | ||
__Caution: Explicitly specifying `undefined` for `booleanDefault` has different meaning from omitting key itself.__ | ||
@example | ||
@@ -234,3 +239,3 @@ ``` | ||
*/ | ||
flags: TypedFlags<Flags> & {[name: string]: unknown}; | ||
flags: TypedFlags<Flags> & Record<string, unknown>; | ||
@@ -240,3 +245,3 @@ /** | ||
*/ | ||
unnormalizedFlags: TypedFlags<Flags> & {[name: string]: unknown}; | ||
unnormalizedFlags: TypedFlags<Flags> & Record<string, unknown>; | ||
@@ -243,0 +248,0 @@ /** |
32
index.js
@@ -57,4 +57,6 @@ 'use strict'; | ||
const buildParserFlags = ({flags, booleanDefault}) => | ||
Object.entries(flags).reduce((parserFlags, [flagKey, flagValue]) => { | ||
const buildParserFlags = ({flags, booleanDefault}) => { | ||
const parserFlags = {}; | ||
for (const [flagKey, flagValue] of Object.entries(flags)) { | ||
const flag = {...flagValue}; | ||
@@ -72,2 +74,3 @@ | ||
flag.type = flag.type ? `${flag.type}-array` : 'array'; | ||
flag.default = flag.default || []; | ||
delete flag.isMultiple; | ||
@@ -77,5 +80,6 @@ } | ||
parserFlags[flagKey] = flag; | ||
} | ||
return parserFlags; | ||
}, {}); | ||
return parserFlags; | ||
}; | ||
@@ -96,7 +100,9 @@ const validateFlags = (flags, options) => { | ||
const foundPkg = readPkgUp.sync({ | ||
cwd: parentDir, | ||
normalize: false | ||
}); | ||
options = { | ||
pkg: readPkgUp.sync({ | ||
cwd: parentDir, | ||
normalize: false | ||
}).packageJson || {}, | ||
pkg: foundPkg ? foundPkg.packageJson : {}, | ||
argv: process.argv.slice(2), | ||
@@ -131,7 +137,9 @@ flags: {}, | ||
parserOptions.configuration = { | ||
...parserOptions.configuration, | ||
'greedy-arrays': false | ||
}; | ||
if (parserOptions['--']) { | ||
parserOptions.configuration = { | ||
...parserOptions.configuration, | ||
'populate--': true | ||
}; | ||
parserOptions.configuration['populate--'] = true; | ||
} | ||
@@ -138,0 +146,0 @@ |
{ | ||
"name": "meow", | ||
"version": "7.1.1", | ||
"version": "8.0.0", | ||
"description": "CLI app helper", | ||
@@ -48,15 +48,15 @@ "license": "MIT", | ||
"minimist-options": "4.1.0", | ||
"normalize-package-data": "^2.5.0", | ||
"normalize-package-data": "^3.0.0", | ||
"read-pkg-up": "^7.0.1", | ||
"redent": "^3.0.0", | ||
"trim-newlines": "^3.0.0", | ||
"type-fest": "^0.13.1", | ||
"yargs-parser": "^18.1.3" | ||
"type-fest": "^0.18.0", | ||
"yargs-parser": "^20.2.3" | ||
}, | ||
"devDependencies": { | ||
"ava": "^2.4.0", | ||
"execa": "^4.0.0", | ||
"execa": "^4.1.0", | ||
"indent-string": "^4.0.0", | ||
"tsd": "^0.11.0", | ||
"xo": "^0.30.0" | ||
"tsd": "^0.13.1", | ||
"xo": "^0.34.1" | ||
}, | ||
@@ -63,0 +63,0 @@ "xo": { |
@@ -146,2 +146,3 @@ # meow [![Build Status](https://travis-ci.org/sindresorhus/meow.svg?branch=master)](https://travis-ci.org/sindresorhus/meow) | ||
- `isMultiple`: Indicates a flag can be set multiple times. Values are turned into an array. (Default: false) | ||
- Multiple values are provided by specifying the flag multiple times, for example, `$ foo -u rainbow -u cat`. Space- or comma-separated values are [currently *not* supported](https://github.com/sindresorhus/meow/issues/164). | ||
@@ -243,5 +244,10 @@ Example: | ||
Value of `boolean` flags not defined in `argv`. | ||
If set to `undefined` the flags not defined in `argv` will be excluded from the result. | ||
If set to `undefined`, the flags not defined in `argv` will be excluded from the result. | ||
The `default` value set in `boolean` flags take precedence over `booleanDefault`. | ||
_Note: If used in conjunction with `isMultiple`, the default flag value is set to `[]`._ | ||
__Caution: Explicitly specifying `undefined` for `booleanDefault` has different meaning from omitting key itself.__ | ||
Example: | ||
@@ -248,0 +254,0 @@ |
23459
410
344
+ Addedhosted-git-info@4.1.0(transitive)
+ Addedlru-cache@6.0.0(transitive)
+ Addednormalize-package-data@3.0.3(transitive)
+ Addedsemver@7.6.2(transitive)
+ Addedtype-fest@0.18.1(transitive)
+ Addedyallist@4.0.0(transitive)
+ Addedyargs-parser@20.2.9(transitive)
- Removedtype-fest@0.13.1(transitive)
- Removedyargs-parser@18.1.3(transitive)
Updatedtype-fest@^0.18.0
Updatedyargs-parser@^20.2.3