[Pkg-javascript-commits] [node-coveralls] 240/332: Use minimist to parse command line options

Bastien Roucariès rouca at moszumanska.debian.org
Thu Nov 9 13:54:06 UTC 2017


This is an automated email from the git hooks/post-receive script.

rouca pushed a commit to branch master
in repository node-coveralls.

commit be2f7b8407e84bd3db1c3d30b2a0b225c9faaf15
Author: Anna Henningsen <sqrt at entless.org>
Date:   Wed Apr 15 17:11:10 2015 +0200

    Use minimist to parse command line options
    
    The command line options are made available as a object
    via `index.options`
---
 index.js               | 9 +++++++++
 lib/logger.js          | 9 +++------
 lib/sendToCoveralls.js | 9 ++-------
 package.json           | 3 ++-
 4 files changed, 16 insertions(+), 14 deletions(-)

diff --git a/index.js b/index.js
index 911cc99..e1103a0 100644
--- a/index.js
+++ b/index.js
@@ -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');
diff --git a/lib/logger.js b/lib/logger.js
index a847a41..f834586 100644
--- a/lib/logger.js
+++ b/lib/logger.js
@@ -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;
 }
diff --git a/lib/sendToCoveralls.js b/lib/sendToCoveralls.js
index 9606a08..fcf63a8 100644
--- a/lib/sendToCoveralls.js
+++ b/lib/sendToCoveralls.js
@@ -1,4 +1,5 @@
 var request = require('request');
+var index = require('../index');
 
 var sendToCoveralls = function(obj, cb){
   var urlBase = 'https://coveralls.io';
@@ -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 {
@@ -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;
diff --git a/package.json b/package.json
index d8f4dfb..24b7237 100644
--- a/package.json
+++ b/package.json
@@ -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",

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-coveralls.git



More information about the Pkg-javascript-commits mailing list