Comparing version 8.0.0 to 8.1.0
@@ -202,2 +202,9 @@ import {PackageJson} from 'type-fest'; | ||
readonly hardRejection?: boolean; | ||
/** | ||
Whether to allow unknown flags or not. | ||
@default true | ||
*/ | ||
readonly allowUnknownFlags?: boolean; | ||
} | ||
@@ -204,0 +211,0 @@ |
21
index.js
@@ -57,2 +57,9 @@ 'use strict'; | ||
const reportUnknownFlags = unknownFlags => { | ||
console.error([ | ||
`Unknown flag${unknownFlags.length > 1 ? 's' : ''}`, | ||
...unknownFlags | ||
].join('\n')); | ||
}; | ||
const buildParserFlags = ({flags, booleanDefault}) => { | ||
@@ -114,2 +121,3 @@ const parserFlags = {}; | ||
hardRejection: true, | ||
allowUnknownFlags: true, | ||
...options | ||
@@ -144,2 +152,7 @@ }; | ||
if (!options.allowUnknownFlags) { | ||
// Collect unknown options in `argv._` to be checked later. | ||
parserOptions.configuration['unknown-options-as-args'] = true; | ||
} | ||
const {pkg} = options; | ||
@@ -183,2 +196,10 @@ const argv = parseArguments(options.argv, parserOptions); | ||
if (!options.allowUnknownFlags) { | ||
const unknownFlags = input.filter(item => typeof item === 'string' && item.startsWith('-')); | ||
if (unknownFlags.length > 0) { | ||
reportUnknownFlags(unknownFlags); | ||
process.exit(2); | ||
} | ||
} | ||
const flags = camelCaseKeys(argv, {exclude: ['--', /^\w$/]}); | ||
@@ -185,0 +206,0 @@ const unnormalizedFlags = {...flags}; |
{ | ||
"name": "meow", | ||
"version": "8.0.0", | ||
"version": "8.1.0", | ||
"description": "CLI app helper", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
@@ -1,2 +0,2 @@ | ||
# meow [![Build Status](https://travis-ci.org/sindresorhus/meow.svg?branch=master)](https://travis-ci.org/sindresorhus/meow) | ||
# meow | ||
@@ -317,2 +317,9 @@ > CLI app helper | ||
#### allowUnknownFlags | ||
Type `boolean`\ | ||
Default: `true` | ||
Whether to allow unknown flags or not. | ||
## Promises | ||
@@ -319,0 +326,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
24124
433
351