aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcainus <[email protected]>2013-06-02 22:44:58 -0700
committercainus <[email protected]>2013-06-02 22:44:58 -0700
commite85a1950a5c8387926a0a52b32b4b068b9daa935 (patch)
tree5a40afc8a4afa85a3a0a0af11acb21b1f43d9232
parent5915e1c88adccdc0a2a8225c6ecc8a5ebf84bb0e (diff)
downloadnode-coveralls-e85a1950a5c8387926a0a52b32b4b068b9daa935.tar.xz
node-coveralls-e85a1950a5c8387926a0a52b32b4b068b9daa935.zip
refactored options parsing out.
-rwxr-xr-xbin/coveralls.js13
-rw-r--r--index.js2
-rw-r--r--lib/getOptions.js37
-rw-r--r--lib/handleInput.js22
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){