Skip to content

Commit

Permalink
fix(*): correct handling of array arguments.
Browse files Browse the repository at this point in the history
  • Loading branch information
mxl committed Feb 4, 2020
1 parent 487c89a commit 0720852
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
4 changes: 3 additions & 1 deletion cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ module.exports = () => {
yargs// eslint-disable-line no-unused-expressions
.strict()
.parserConfiguration({
'duplicate-arguments-array': false,
'populate--': true
})
.usage('flavors - print loaded configuration or configure environment and run command.')
Expand Down Expand Up @@ -133,7 +134,8 @@ module.exports = () => {
},
'loader': {
alias: 'l',
describe: 'Name of a Node.js module or a path to it'
array: true,
describe: 'Loaders. Names of a Node.js modules or their paths.'
},
'name': {
alias: 'n',
Expand Down
13 changes: 6 additions & 7 deletions test/cli/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ function runWithCwdOutputEqual(expected, cwd, args, env = {}) {
return outputEqual(expected, ['run', ...args], cwd, env);
}

function runWithWorkingDirOutputEqual(expected, workingDir, name, args, env = {}) {
return outputEqual(expected, ['run', '-w', workingDir, '-n', name, ...args], '', env);
function runWithWorkingDirOutputEqual(expected, workingDir, name, command, options = [], env = {}) {
return outputEqual(expected, ['-w', workingDir, '-n', name, ...options, 'run', ...command], '', env);
}

function printOutputEqual(expected, workingDir, name, args = [], env = {}) {
Expand All @@ -38,10 +38,9 @@ describe('CLI', () => {
it('runs runs command with dash options', () => runWithWorkingDirOutputEqual('-t 1', 'commonTest', 'a', ['echo', '--', '-t', '1']));
it('runs runs command with double-dash options', () => runWithWorkingDirOutputEqual('--test 1', 'commonTest', 'a', ['echo', '--', '--test', '1']));
it('flattens config', () => runWithWorkingDirOutputEqual('1', 'nested', 'a', ['echo $nested_value']));
it('applies configDirName', () => runWithWorkingDirOutputEqual('1', 'configDirName', 'a', ['-d', 'config', 'echo $value']));
it('applies configFileName', () => runWithWorkingDirOutputEqual('1', 'configFileName', 'a', ['-f', 'custom', 'echo $value']));
it('applies loaders', () => runWithWorkingDirOutputEqual('123', 'loaders', 'a-b-c', ['-l', testPath('..', '..', 'jsonLoader.js'), '-l',
testPath('..', '..', 'jsLoader.js'), '-l', 'flavors-loader-yaml', 'echo $value1$value2$value3']));
it('applies configDirName', () => runWithWorkingDirOutputEqual('1', 'configDirName', 'a', ['echo $value'], ['-d', 'config']));
it('applies configFileName', () => runWithWorkingDirOutputEqual('1', 'configFileName', 'a', ['echo $value'], ['-f', 'custom']));
it('applies loaders', () => runWithWorkingDirOutputEqual('123', 'loaders', 'a-b-c', ['echo $value1$value2$value3', '-l', testPath('..', '..', 'jsonLoader.js'), testPath('..', '..', 'jsLoader.js'), 'flavors-loader-yaml']));
it('uses options from flavors options file: ' + cli.optionsFile,
() => runWithCwdOutputEqual('2', 'flavorsOptions', ['echo', '$value'], {FLAVORS_CONFIG_NAME: 'test'}));

Expand Down Expand Up @@ -84,4 +83,4 @@ describe('CLI', () => {
() => runWithCwdOutputEqual('2', 'optionsFile', ['-n', 'test', '-o', testPath('optionsFile', 'customOptionsFile.js'), 'echo', '$value']));

it('runs plugin', () => runWithWorkingDirOutputEqual('1', 'plugin', 'a', ['-p', testPath('plugin', 'plugin.js')]));
});
});

0 comments on commit 0720852

Please sign in to comment.