Skip to content

Commit e08eb4d

Browse files
authoredMay 11, 2020
Fix isMultiple not handling multi-word flags (#150)
1 parent e3301ed commit e08eb4d

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed
 

‎index.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
const path = require('path');
33
const buildParserOptions = require('minimist-options');
44
const yargs = require('yargs-parser');
5+
const camelCase = require('camelcase');
56
const camelcaseKeys = require('camelcase-keys');
67
const decamelizeKeys = require('decamelize-keys');
78
const trimNewlines = require('trim-newlines');
@@ -83,7 +84,7 @@ Convert to alternative syntax for coercing values to expected type, according to
8384
const convertToTypedArrayOption = (arrayOption, flags) =>
8485
arrify(arrayOption).map(flagKey => ({
8586
key: flagKey,
86-
[flags[flagKey].type || 'string']: true
87+
[flags[camelCase(flagKey, '-')].type || 'string']: true
8788
}));
8889

8990
const validateFlags = (flags, options) => {

‎package.json

+1
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
"dependencies": {
4343
"@types/minimist": "^1.2.0",
4444
"arrify": "^2.0.1",
45+
"camelcase": "^6.0.0",
4546
"camelcase-keys": "^6.2.2",
4647
"decamelize-keys": "^1.1.0",
4748
"hard-rejection": "^2.1.0",

‎test/test.js

+15
Original file line numberDiff line numberDiff line change
@@ -482,6 +482,21 @@ test('isMultiple - multiple flag default values', t => {
482482
});
483483
});
484484

485+
// Happened in production 2020-05-10: https://github.com/sindresorhus/meow/pull/143#issuecomment-626287226
486+
test('isMultiple - handles multi-word flag name', t => {
487+
t.deepEqual(meow({
488+
argv: ['--foo-bar=baz'],
489+
flags: {
490+
fooBar: {
491+
type: 'string',
492+
isMultiple: true
493+
}
494+
}
495+
}).flags, {
496+
fooBar: ['baz']
497+
});
498+
});
499+
485500
if (NODE_MAJOR_VERSION >= 14) {
486501
test('supports es modules', async t => {
487502
try {

0 commit comments

Comments
 (0)
Please sign in to comment.