From 6f158abaf923dad6878a64da2d8a3c2c56ae604f Mon Sep 17 00:00:00 2001 From: Vojta Jina Date: Fri, 2 Aug 2013 18:38:07 -0700 Subject: [PATCH] fix(runner): do not confuse client args with the config file We have to split the args after `--`. --- lib/cli.js | 10 +++++++++- test/unit/cli.spec.coffee | 6 ++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/lib/cli.js b/lib/cli.js index 3fe75fcf4..b30f28ced 100644 --- a/lib/cli.js +++ b/lib/cli.js @@ -94,6 +94,13 @@ var parseClientArgs = function(argv) { return clientArgs; }; +// return only args that occur before `--` +var argsBeforeDoubleDash = function(argv) { + var idx = argv.indexOf('--'); + + return idx === -1 ? argv : argv.slice(0, idx); +}; + var describeShared = function() { optimist @@ -170,7 +177,7 @@ var describeCompletion = function() { exports.process = function() { - var argv = optimist.argv; + var argv = optimist.parse(argsBeforeDoubleDash(process.argv.slice(2))); var options = { cmd: argv._.shift() }; @@ -211,3 +218,4 @@ exports.process = function() { // just for testing exports.processArgs = processArgs; exports.parseClientArgs = parseClientArgs; +exports.argsBeforeDoubleDash = argsBeforeDoubleDash; diff --git a/test/unit/cli.spec.coffee b/test/unit/cli.spec.coffee index ef227fa8c..b2d1a96fa 100644 --- a/test/unit/cli.spec.coffee +++ b/test/unit/cli.spec.coffee @@ -136,3 +136,9 @@ describe 'cli', -> it 'should return empty args if -- is not present', -> args = cli.parseClientArgs ['node', 'karma.js', 'runArg', '--flag', '--foo', '--bar', 'baz'] expect(args).to.deep.equal [] + + + describe 'argsBeforeDoubleDash', -> + it 'should return array of args that occur before --', -> + args = cli.argsBeforeDoubleDash ['aa', '--bb', 'value', '--', 'some', '--no-more'] + expect(args).to.deep.equal ['aa', '--bb', 'value']