
// deepak_node.js

'use strict';

var fs   = require('fs');
var path = require('path');

var app  = require('commander');

app.version('1.0.1')
   .option('-c, --count [pos integer]', 'Count of Choprifications to deliver')
   .option('--source [filename]',       'Provide your own source datafiles')
   .parse(process.argv);





function DeepakGenerator() {



    var libdir = path.join(path.dirname(fs.realpathSync(__filename)), '../lib');
    var source = app.source || path.join(libdir, '/default_deepak_data.json');
    var count  = parseInt(app.c || app.count || '1', 10);



    function randFrom(X) {
        return X[ Math.floor(Math.random() * X.length) ];
    }

    function makeDC(Data) {
        var out = '';
        for (var i in Data.pattern) { out += randFrom(Data[Data.pattern[i]]); }
        return out;
    }



    if (fs.existsSync(source)) {
        
        var Data = require(source);

        for (var i=0; i<count; ++i) {
            console.log(makeDC(Data));
        }

    } else {
        console.log('\nFatal error: requested source datafile does not exist.\n  "' + source + '"');
    }



console.log('Passed through');



}
console.log('Passed behind');





exports.choprify = DeepakGenerator;
console.log('Passed out');

@@ -1,8 +1,29 @@
+%0A/*jshint node:true*/
 %0A// deep
@@ -1143,73 +1143,9 @@
 %0A%0A%0A%0A
-console.log('Passed through');%0A%0A%0A%0A%7D%0Aconsole.log('Passed behind');
+%7D
 %0A%0A%0A%0A
@@ -1186,31 +1186,4 @@
 or;%0A
-console.log('Passed out');%0A

remove stray console logs; jshint setup