Permalink
Please sign in to comment.
Browse files
Update cli handling to use latest bagofholding, first go at updating …
…tests to use busterjs.
- Loading branch information...
Showing
with
208 additions
and 256 deletions.
- +16 −0 conf/commands.json
- +16 −29 lib/cli.js
- +2 −2 lib/functions.js
- +7 −9 package.json
- +2 −1 test/cli.js
- +2 −1 test/datagen.js
- +161 −213 test/functions.js
- +2 −1 test/worker.js
@@ -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
lib/cli.js
@@ -1,40 +1,27 @@ | ||
-var _ = require('underscore'), | ||
- bag = require('bagofholding'), | ||
- fs = require('fs'), | ||
- p = require('path'), | ||
- datagen = require('./datagen'); | ||
+var bag = require('bagofholding'), | ||
+ DataGen = require('./datagen'); | ||
+ | ||
+function _init() { | ||
+ 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 _init() { | ||
- new datagen().init(bag.cli.exit); | ||
- } | ||
- | ||
- 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 | ||
+ var actions = { | ||
+ commands: { | ||
+ init: { action: _init }, | ||
+ gen: { action: _generate } | ||
} | ||
}; | ||
- bag.cli.parse(commands, __dirname); | ||
+ bag.cli.command(__dirname, actions); | ||
} | ||
exports.exec = exec; |
16
package.json

Oops, something went wrong.
0 comments on commit
6f82250