Skip to content

Commit

Permalink
fix(runner): do not confuse client args with the config file
Browse files Browse the repository at this point in the history
We have to split the args after `--`.
  • Loading branch information
vojtajina committed Aug 3, 2013
1 parent 449e4a1 commit 6f158ab
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
10 changes: 9 additions & 1 deletion lib/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
};
Expand Down Expand Up @@ -211,3 +218,4 @@ exports.process = function() {
// just for testing
exports.processArgs = processArgs;
exports.parseClientArgs = parseClientArgs;
exports.argsBeforeDoubleDash = argsBeforeDoubleDash;
6 changes: 6 additions & 0 deletions test/unit/cli.spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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']

0 comments on commit 6f158ab

Please sign in to comment.