Skip to content

Commit

Permalink
PR #120 - Merge branch 'walk_options' of https://github.com/andrewnic…
Browse files Browse the repository at this point in the history
  • Loading branch information
caridy committed Apr 15, 2014
2 parents 930273f + fd08a3e commit 1227ffe
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 1 deletion.
29 changes: 29 additions & 0 deletions lib/args.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,34 @@ var clean = function(args) {
return parsed;
};

// Get the base arguments list without defaults applied.
var baseOptions = function(args) {
var options = {},
key;

// Get any supplied arguments if not specified.
if (!args) {
args = clean();
}

// Define all of the base arguments.
for (key in known) {
if (known.hasOwnProperty(key)) {
options[key] = undefined;
}
}

// Add any supplied overrides.
for (key in args) {
// And override with the specified arguments.
if (args.hasOwnProperty(key)) {
options[key] = args[key];
}
}

return options;
};

var setDefaults = function(parsed) {
if (parsed === undefined) {
parsed = clean();
Expand Down Expand Up @@ -113,6 +141,7 @@ var parse = function (args) {
};

exports.defaults = setDefaults;
exports.baseOptions = baseOptions;
exports.has = has;
exports.raw = raw;
exports.parse = parse;
Expand Down
4 changes: 3 additions & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,9 @@ exports.init = function (opts, initCallback) {
} else {
if (options.walk) {
walk = require('./walk');
walk.run(options, initCallback);
// Use the less-processed opts here instead - we don't want the defaults to override the individual
// Shifter configurations.
walk.run(args.baseOptions(opts), initCallback);
} else {
log.warn('no ' + buildFileName + ' file, downshifting to convert ant files');
ant = require('./ant');
Expand Down
35 changes: 35 additions & 0 deletions tests/1-args.js
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,41 @@ var tests = {
assert.isFalse(topic.quiet);
assert.isFalse(topic.cache);
}
},
'args.baseOptions should define all of the standard options': {
topic: function() {
return args.baseOptions();
},
'should default undefined': function(topic) {
assert.isTrue(topic.hasOwnProperty('walk') && topic.walk === undefined);
assert.isTrue(topic.hasOwnProperty('cache') && topic.cache === undefined);
assert.isTrue(topic.hasOwnProperty('lint') && topic.lint === undefined);
},
'should not have undefined values': function(topic) {
assert.isFalse(topic.hasOwnProperty('foo'));
assert.isFalse(topic.hasOwnProperty('bar'));
assert.isFalse(topic.hasOwnProperty('baz'));
}
},
'args.baseOptions should allow CLI overrides of options': {
topic: function() {
return args.baseOptions({
cache: true,
lint: 'config'
});
},
'should allow overrides': function(topic) {
assert.isTrue(topic.cache);
assert.equal('config', topic.lint);
},
'should default undefined': function(topic) {
assert.isTrue(topic.hasOwnProperty('walk') && topic.walk === undefined);
},
'should not have undefined values': function(topic) {
assert.isFalse(topic.hasOwnProperty('foo'));
assert.isFalse(topic.hasOwnProperty('bar'));
assert.isFalse(topic.hasOwnProperty('baz'));
}
}
};

Expand Down

0 comments on commit 1227ffe

Please sign in to comment.