Skip to content

Commit

Permalink
Use minimist to parse command line options
Browse files Browse the repository at this point in the history
The command line options are made available as a object
via `index.options`
  • Loading branch information
addaleax committed Dec 10, 2015
1 parent 879fb9e commit be2f7b8
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 14 deletions.
9 changes: 9 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
var minimist = require('minimist');

// this needs to go before the other require()s so that
// the other files can already use index.options
exports.options = minimist(process.argv.slice(2), {
boolean: ['verbose', 'stdout'],
alias: { 'v': 'verbose', 's': 'stdout' }
});

var dir = './lib/';
exports.convertLcovToCoveralls = require(dir + 'convertLcovToCoveralls');
exports.sendToCoveralls = require(dir + 'sendToCoveralls');
Expand Down
9 changes: 3 additions & 6 deletions lib/logger.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
var index = require('../index');

module.exports = function(){
return require('log-driver')({level : getLogLevel()});
};

function getLogLevel(){
if (hasVerboseCommandLineOption() || hasDebugEnvVariable()) {
if (index.options.verbose || hasDebugEnvVariable()) {
return 'warn';
}
return 'error';
}

function hasVerboseCommandLineOption(){
// look into command line arguments starting from index 2
return process.argv.slice(2).filter(RegExp.prototype.test.bind(/^(-v|--verbose)$/)).length > 0;
}

function hasDebugEnvVariable(){
return process.env.NODE_COVERALLS_DEBUG == 1;
}
9 changes: 2 additions & 7 deletions lib/sendToCoveralls.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
var request = require('request');
var index = require('../index');

var sendToCoveralls = function(obj, cb){
var urlBase = 'https://coveralls.io';
Expand All @@ -9,7 +10,7 @@ var sendToCoveralls = function(obj, cb){
var str = JSON.stringify(obj);
var url = urlBase + '/api/v1/jobs';

if (hasWriteToStdoutOption()) {
if (index.options.stdout) {
process.stdout.write(str);
cb(null, { statusCode: 200 }, '');
} else {
Expand All @@ -19,10 +20,4 @@ var sendToCoveralls = function(obj, cb){
}
};

function hasWriteToStdoutOption(){
// look into command line arguments starting from index 2
return process.argv.slice(2).filter(RegExp.prototype.test.bind(/^(-s|--stdout)$/)).length > 0;
}


module.exports = sendToCoveralls;
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@
"js-yaml": "3.0.1",
"lcov-parse": "0.0.6",
"log-driver": "1.2.4",
"request": "2.67.0"
"request": "2.67.0",
"minimist": "1.2.0"
},
"devDependencies": {
"sinon-restore": "1.0.0",
Expand Down

0 comments on commit be2f7b8

Please sign in to comment.