Permalink
Browse files

Merge branch 'commander'

  • Loading branch information...
2 parents 57fe0f9 + 88a01af commit 177372dfd1983c4f337f3561d53fd6a1f1e00c51 @tj committed Aug 19, 2011
Showing with 31 additions and 76 deletions.
  1. +7 −0 History.md
  2. +19 −74 bin/stats
  3. +1 −1 lib/stats.js
  4. +4 −1 package.json
View
@@ -1,4 +1,11 @@
+0.0.6 / 2011-08-15
+==================
+
+ * Added `commander` dependency
+ * Changed stats(1) to use the commander module
+ * Fixed error messages for files not found (now throwing)
+
0.0.5 / 2011-08-03
==================
View
@@ -5,21 +5,10 @@
*/
var stats = require('../')
+ , program = require('commander')
, fs = require('fs');
/**
- * Arguments.
- */
-
-var args = process.argv.slice(2);
-
-/**
- * Paths to process.
- */
-
-var paths = [];
-
-/**
* Statistics.
*/
@@ -29,77 +18,33 @@ var statistics = {};
* Options.
*/
-var options = { format: 'text' };
+program
+ .version(stats.version)
+ .option('-f, --format <name>', 'output the given format. text or json. [text]', 'text')
+ .option('-j, --json', 'output json stats')
+ .option('-t, --text', 'output human-readable text stats')
+ .option('-T, --totals', 'output totals only')
+ .parse(process.argv);
-/**
- * Usage docs.
- */
+// format shortcuts
-var usage = [
- ''
- , ' Usage: stats [options] [file|dir ...]'
- , ''
- , ' Options:'
- , ''
- , ' -f, --format <name> Output the given format. text, json'
- , ' -I, --ignore-errors Ignore parse errors'
- , ' -j, --json Output JSON statistics'
- , ' -t, --text Output human-readable plain-text stats'
- , ' -T, --totals Output totals only'
- , ' -V, --version Display the version of stats'
- , ' -h, --help Display help information'
- , ''
-].join('\n');
+if (program.text) program.format = 'text';
+if (program.json) program.format = 'json';
-/**
- * Handle arguments.
- */
-args.length > 0 || args.push('-h');
+// paths
-var arg;
-while (args.length) {
- arg = args.shift();
- switch (arg) {
- case '-h':
- case '--help':
- case 'help':
- console.log(usage);
- process.exit(1);
- case '-V':
- case '--version':
- console.log(stats.version);
- process.exit(0);
- break;
- case '-j':
- case '--json':
- options.format = 'json';
- break;
- case '-t':
- case '--text':
- options.format = 'text';
- break;
- case '-I':
- case '--ignore-errors':
- options.ignoreParseErrors = true;
- break;
- case '-T':
- case '--totals':
- options.totalsOnly = true;
- break;
- default:
- paths.push(arg);
- }
-}
+var paths = program.args;
// process
var totals = {};
stats.find(paths, function(err, files){
+ if (err) throw err;
var pending = files.length;
files.forEach(function(file){
fs.readFile(file, 'utf8', function(err, str){
if (err) throw err;
- statistics[file] = stats.parse(str, options);
+ statistics[file] = stats.parse(str, program);
Object.keys(statistics[file]).forEach(function(key){
totals[key] = (totals[key] || 0) + statistics[file][key];
});
@@ -111,12 +56,12 @@ stats.find(paths, function(err, files){
// finished
function done() {
- if (options.text) {}
- var format = stats.formats[options.format];
- if (!format) throw new Error('invalid format "' + options.format + '"');
+ if (program.text) {}
+ var format = stats.formats[program.format];
+ if (!format) throw new Error('invalid format "' + program.format + '"');
var obj = { totals: totals };
totals.files = Object.keys(statistics).length;
- if (!options.totalsOnly) {
+ if (!program.totals) {
for (var file in statistics) obj[file] = statistics[file];
}
format(obj);
View
@@ -9,7 +9,7 @@
* Library version.
*/
-exports.version = '0.0.5';
+exports.version = '0.0.6';
/**
* Return stats for the given javascript `str`.
View
@@ -1,12 +1,15 @@
{
"name": "stats"
- , "version": "0.0.5"
+ , "version": "0.0.6"
, "description": "JavaScript statistics (LOC, SLOC, etc)"
, "keywords": ["metrics", "stats", "statistics", "sloc", "uglify"]
, "author": "TJ Holowaychuk <tj@vision-media.ca>"
, "bin": {
"stats": "./bin/stats"
}
+ , "dependencies": {
+ "commander": "0.0.4"
+ }
, "devDependencies": {
"should": ">= 0.0.1"
}

0 comments on commit 177372d

Please sign in to comment.