Skip to content

Commit

Permalink
feat(cli): parseArgs now supports --node-args="..." syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
smelukov committed Jan 30, 2020
1 parent 4bfff9c commit 2ac6ff9
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
3 changes: 1 addition & 2 deletions lib/bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ async function runCLI(cli, commandIsUsed) {
let args;
const helpFlagExists = isFlagPresent(process.argv, 'help');
const versionFlagExists = isFlagPresent(process.argv, 'version');
const nodeArgsExists = isFlagPresent(process.argv, 'node-args');
const nodeArgsExists = process.argv.find(arg => arg.includes('--node-args'));

if (helpFlagExists) {
cli.runHelp(process.argv);
Expand Down Expand Up @@ -111,7 +111,6 @@ async function runCLI(cli, commandIsUsed) {
const newArgKeys = Object.keys(argsMap).filter(arg => !keysToDelete.includes(argsMap[arg].pos));
// eslint-disable-next-line require-atomic-updates
process.argv = newArgKeys;
args = cmdArgs(core, { stopAtFirstUnknown: false, partial: true });

await cli.run(args, core);
process.stdout.write('\n');
Expand Down
3 changes: 3 additions & 0 deletions lib/utils/parse-args.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ module.exports = rawArgs => {
for (const value of rawArgs) {
if (value === '--node-args') {
isNodeArg = true;
} else if (value.startsWith('--node-args=')) {
const [, argValue] = value.match(/^--node-args="?(.+?)"?$/);
nodeArgs.push(argValue);
} else if (isNodeArg) {
isNodeArg = false;
nodeArgs.push(...value.split(' '));
Expand Down
4 changes: 2 additions & 2 deletions test/node/node.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ describe('node flags', () => {
expectedNodeArgs: ['--name1=value1', '--name2', 'value2'],
},
{
rawArgs: ['--node-args', '--name1=value1', '--node-args', '--name2 value2', '--node-args', '-n=v', '--node-args', '-k v'],
rawArgs: ['--node-args', '--name1=value1', '--node-args', '--name2="value2"', '--node-args', '--name3 value3', '--node-args', '-k v'],
expectedCliArgs: [],
expectedNodeArgs: ['--name1=value1', '--name2', 'value2', '-n=v', '-k', 'v'],
expectedNodeArgs: ['--name1=value1', '--name2="value2"', '--name3', 'value3', '-k', 'v'],
},
].map(({ rawArgs, expectedNodeArgs, expectedCliArgs }) => {
const { nodeArgs, cliArgs } = parseArgs(rawArgs);
Expand Down

0 comments on commit 2ac6ff9

Please sign in to comment.