Skip to content

Commit

Permalink
Update cli handling to use latest bagofholding, first go at updating …
Browse files Browse the repository at this point in the history
…tests to use busterjs.
  • Loading branch information
cliffano committed Mar 7, 2013
1 parent 9b82277 commit 6f82250
Show file tree
Hide file tree
Showing 8 changed files with 208 additions and 256 deletions.
16 changes: 16 additions & 0 deletions conf/commands.json
@@ -0,0 +1,16 @@
{
"commands": {
"init": {
"desc": "Create sample template files\nUsage: datagen init"
},
"gen": {
"desc": "Generate data file\nUsage: datagen [-i/--gen-id <genId>] [-s/--num-segments <numSegments>] [-w/--num-workers <numWorkers>] [-o/--out-file <outFile>] gen",
"options": [
{ "arg": "-i, --gen-id <genId>", "desc": "An ID unique to the current data generation, used by all worker processes | defaut: datagen process PID" },
{ "arg": "-s, --num-segments <numSegments>", "desc": "How many segments in a data file | default: 1" },
{ "arg": "-w, --num-workers <numWorkers>", "desc": "How many worker processes, each worker creates a data file | default: 1" },
{ "arg": "-o, --out-file <outFile>", "desc": "Generated data file name, postfixed with worker ID | default: 'data'" }
]
}
}
}
45 changes: 16 additions & 29 deletions lib/cli.js
@@ -1,40 +1,27 @@
var _ = require('underscore'), var bag = require('bagofholding'),
bag = require('bagofholding'), DataGen = require('./datagen');
fs = require('fs'),
p = require('path'), function _init() {
datagen = require('./datagen'); new DataGen().init(bag.cli.exit);
}

function _generate(args) {
new DataGen().generate(args.genId, parseInt(args.numSegments, 10), parseInt(args.numWorkers, 10), args.outFile, bag.cli.exit);
}


/** /**
* Execute datagen using header, segment, and footer files in the current directory. * Execute DataGen CLI.
*/ */
function exec() { function exec() {


function _init() { var actions = {
new datagen().init(bag.cli.exit); commands: {
} init: { action: _init },

gen: { action: _generate }
function _generate(args) {
new datagen().generate(args.genId, args.numSegments, args.numWorkers, args.outFile, bag.cli.exit);
}

var commands = {
init: {
desc: 'Create example template files',
action: _init
},
gen: {
desc: 'Generate data file',
options: [
{ arg: '-i, --gen-id <genId>', desc: 'An ID unique to the current data generation, used by all worker processes | defaut: datagen process PID' },
{ arg: '-s, --num-segments <numSegments>', desc: 'How many segments in a data file | default: 1', action: parseInt },
{ arg: '-w, --num-workers <numWorkers>', desc: 'How many worker processes, each worker creates a data file | default: 1', action: parseInt },
{ arg: '-o, --out-file <outFile>', desc: 'Generated data file name, postfixed with worker ID | default: \'data\'' }
],
action: _generate
} }
}; };


bag.cli.parse(commands, __dirname); bag.cli.command(__dirname, actions);
} }


exports.exec = exec; exports.exec = exec;
4 changes: 2 additions & 2 deletions lib/functions.js
@@ -1,7 +1,7 @@
var dateFormat = require('dateformat'), var dateFormat = require('dateformat'),
faker = require('Faker'), faker = require('Faker'),
nonsense = require('Nonsense'), Nonsense = require('Nonsense'),
ns = new nonsense(); ns = new Nonsense();


/** /**
* Template function to generate a random integer. * Template function to generate a random integer.
Expand Down
16 changes: 7 additions & 9 deletions package.json
Expand Up @@ -31,17 +31,15 @@
"test": "./test" "test": "./test"
}, },
"dependencies": { "dependencies": {
"bagofholding": "0.0.12", "bagofholding": "0.1.2",
"dateformat": "1.0.2-1.2.3", "dateformat": "1.0.4-1.2.3",
"Faker": "0.1.3", "Faker": "0.5.6",
"ncp": "0.2.6", "ncp": "0.4.0",
"Nonsense": "0.1.2", "Nonsense": "0.1.2",
"underscore": "1.3.3" "underscore": "1.4.4"
}, },
"devDependencies": { "devDependencies": {
"mocha": "1.3.2", "buster": "0.6.12"
"sandboxed-module": "0.1.3",
"should": "1.1.0"
}, },
"scripts": {}, "scripts": {},
"engines": { "engines": {
Expand All @@ -53,4 +51,4 @@
"url": "http://github.com/cliffano/datagen/raw/master/LICENSE" "url": "http://github.com/cliffano/datagen/raw/master/LICENSE"
} }
] ]
} }
3 changes: 2 additions & 1 deletion test/cli.js
@@ -1,3 +1,4 @@
/*
var bag = require('bagofholding'), var bag = require('bagofholding'),
sandbox = require('sandboxed-module'), sandbox = require('sandboxed-module'),
should = require('should'), should = require('should'),
Expand Down Expand Up @@ -84,4 +85,4 @@ describe('cli', function () {
}); });
}); });
}); });
*/
3 changes: 2 additions & 1 deletion test/datagen.js
@@ -1,3 +1,4 @@
/*
var bag = require('bagofholding'), var bag = require('bagofholding'),
_jscov = require('../lib/datagen'), _jscov = require('../lib/datagen'),
sandbox = require('sandboxed-module'), sandbox = require('sandboxed-module'),
Expand Down Expand Up @@ -96,4 +97,4 @@ describe('datagen', function () {
}); });
}); });
}); });
*/

0 comments on commit 6f82250

Please sign in to comment.