[Pkg-javascript-commits] [node-coveralls] 46/332: refactored options parsing out.
Bastien Roucariès
rouca at moszumanska.debian.org
Thu Nov 9 13:53:38 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 e85a1950a5c8387926a0a52b32b4b068b9daa935
Author: cainus <gregg at caines.ca>
Date: Sun Jun 2 22:44:58 2013 -0700
refactored options parsing out.
---
bin/coveralls.js | 13 +------------
index.js | 2 ++
lib/getOptions.js | 37 +++++++++++++++++++++++++++++++++++++
lib/handleInput.js | 22 +++++-----------------
4 files changed, 45 insertions(+), 29 deletions(-)
diff --git a/bin/coveralls.js b/bin/coveralls.js
index ba05eec..b003b15 100755
--- a/bin/coveralls.js
+++ b/bin/coveralls.js
@@ -2,17 +2,6 @@
var handleInput = require('../lib/handleInput');
var logger = require('../lib/logger');
-var options = {};
-
-if (process.argv[2]) {
- if (~['-v', '--verbose'].indexOf(process.argv[2])) {
- if (process.argv[3]) {
- options.filepath = process.argv[3];
- }
- } else {
- options.filepath = process.argv[2];
- }
-}
process.stdin.resume();
process.stdin.setEncoding('utf8');
@@ -24,6 +13,6 @@ process.stdin.on('data', function(chunk) {
});
process.stdin.on('end', function() {
- handleInput(input, options);
+ handleInput(input);
});
diff --git a/index.js b/index.js
index 7bd3e60..3bef933 100644
--- a/index.js
+++ b/index.js
@@ -4,4 +4,6 @@ if (process.env.COVERALLS_COVERAGE){
}
exports.convertLcovToCoveralls = require(dir + 'convertLcovToCoveralls');
exports.sendToCoveralls = require(dir + 'sendToCoveralls');
+exports.getOptions = require(dir + 'getOptions');
exports.handleInput = require(dir + 'handleInput');
+
diff --git a/lib/getOptions.js b/lib/getOptions.js
new file mode 100644
index 0000000..f314b00
--- /dev/null
+++ b/lib/getOptions.js
@@ -0,0 +1,37 @@
+var fs = require('fs');
+var path = require('path');
+var YAML = require('libyaml');
+var logger = require('./logger');
+
+var getOptions = function(){
+ var options = {};
+
+ // try to get filepath from the command-line
+ if (process.argv[2]) {
+ if (~['-v', '--verbose'].indexOf(process.argv[2])) {
+ if (process.argv[3]) {
+ options.filepath = process.argv[3];
+ }
+ } else {
+ options.filepath = process.argv[2];
+ }
+ }
+
+ // try to get the repo token as an environment variable
+ if (process.env.COVERALLS_REPO_TOKEN) {
+ options.repo_token = process.env.COVERALLS_REPO_TOKEN;
+ } else {
+ // try to get the repo token from a .coveralls.yml file
+ var yml = path.join(process.cwd(), '.coveralls.yml');
+ try {
+ if (fs.statSync(yml).isFile()) {
+ options.repo_token = YAML.readFileSync(yml)[0].repo_token;
+ }
+ } catch(ex){
+ logger.warn("Repo token could not be determined. Continuing without it.");
+ }
+ }
+ return options;
+};
+
+module.exports = getOptions;
diff --git a/lib/handleInput.js b/lib/handleInput.js
index af850c6..682a439 100644
--- a/lib/handleInput.js
+++ b/lib/handleInput.js
@@ -1,25 +1,13 @@
-var fs = require('fs');
-var path = require('path');
-var YAML = require('libyaml');
var sendToCoveralls = require('../index').sendToCoveralls;
var convertLcovToCoveralls = require('../index').convertLcovToCoveralls;
var logger = require('./logger');
+console.log("index: ", require('../index'));
+var getOptions = require('../index').getOptions;
-var handleInput = function(input, options){
+var handleInput = function(input){
logger.debug(input);
-
- if (process.env.COVERALLS_REPO_TOKEN) {
- options.repo_token = process.env.COVERALLS_REPO_TOKEN;
- } else {
- var yml = path.join(process.cwd(), '.coveralls.yml');
- try {
- if (fs.statSync(yml).isFile()) {
- options.repo_token = YAML.readFileSync(yml)[0].repo_token;
- }
- } catch(ex){
- logger.warn("Repo token could not be determined. Continuing without it.");
- }
- }
+ var options = getOptions();
+ logger.debug(options);
convertLcovToCoveralls(input, options, function(err, postData){
if (err){
--
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