From e08eb4dbc5039744149323c6d0976a9789900a5c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oskar=20L=C3=B6fgren?= Date: Mon, 11 May 2020 15:54:46 +0200 Subject: [PATCH] Fix `isMultiple` not handling multi-word flags (#150) --- index.js | 3 ++- package.json | 1 + test/test.js | 15 +++++++++++++++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 559366d..7df0ff7 100644 --- a/index.js +++ b/index.js @@ -2,6 +2,7 @@ const path = require('path'); const buildParserOptions = require('minimist-options'); const yargs = require('yargs-parser'); +const camelCase = require('camelcase'); const camelcaseKeys = require('camelcase-keys'); const decamelizeKeys = require('decamelize-keys'); const trimNewlines = require('trim-newlines'); @@ -83,7 +84,7 @@ Convert to alternative syntax for coercing values to expected type, according to const convertToTypedArrayOption = (arrayOption, flags) => arrify(arrayOption).map(flagKey => ({ key: flagKey, - [flags[flagKey].type || 'string']: true + [flags[camelCase(flagKey, '-')].type || 'string']: true })); const validateFlags = (flags, options) => { diff --git a/package.json b/package.json index 9cf0470..6fa86b2 100644 --- a/package.json +++ b/package.json @@ -42,6 +42,7 @@ "dependencies": { "@types/minimist": "^1.2.0", "arrify": "^2.0.1", + "camelcase": "^6.0.0", "camelcase-keys": "^6.2.2", "decamelize-keys": "^1.1.0", "hard-rejection": "^2.1.0", diff --git a/test/test.js b/test/test.js index 946a069..a3c9714 100644 --- a/test/test.js +++ b/test/test.js @@ -482,6 +482,21 @@ test('isMultiple - multiple flag default values', t => { }); }); +// Happened in production 2020-05-10: https://github.com/sindresorhus/meow/pull/143#issuecomment-626287226 +test('isMultiple - handles multi-word flag name', t => { + t.deepEqual(meow({ + argv: ['--foo-bar=baz'], + flags: { + fooBar: { + type: 'string', + isMultiple: true + } + } + }).flags, { + fooBar: ['baz'] + }); +}); + if (NODE_MAJOR_VERSION >= 14) { test('supports es modules', async t => { try {