diff --git a/README.md b/README.md index de3b6b6..f8f1d71 100644 --- a/README.md +++ b/README.md @@ -45,8 +45,9 @@ $ npm install --save datamaker - `--template`/`-t` - the path of the template file e.g `--template /path/to/template.txt` - `--format`/`-f` - the target file format (`none`, `csv`, `json` or `xml`). Default `none` e.g. `--format json` +- `--pretty`/`-p` - Pretty Print the output. only avaible for `json`. Default: `false` - `--iterations`/`-i` - the number of records to create. Default `1` e.g. `--iterations 5000` -- `--list`/`-l` - list the available tags +- `--list`/`-l` - list the available tags ## Generating CSV files diff --git a/bin/datamaker.bin.js b/bin/datamaker.bin.js index e9d898b..d174296 100755 --- a/bin/datamaker.bin.js +++ b/bin/datamaker.bin.js @@ -9,7 +9,8 @@ let rs = null // get command-line arguements var argv = require('yargs') .option('format', { alias: ['f', 'type'], describe: 'Format of output data: json,csv,none', demandOption: false, default: 'none' }) - .option('iterations', { alias: 'i', describe: 'Number of records to generater', demandOption: false, default: 1 }) + .option('pretty', { alias: 'p', boolean: true, describe: 'Pretty-Print JSON-Files', demandOption: false, default: false }) + .option('iterations', { alias: 'i', describe: 'Number of records to generate', demandOption: false, default: 1 }) .option('template', { alias: 't', describe: 'The path of the template file', demandOption: false }) .option('list', { alias: 'l', boolean: true, describe: 'List available tags', demandOption: false, default: false }) .help('help') @@ -51,7 +52,13 @@ rs.on('readable', () => { }).on('end', () => { // when the template has loaded, generate the data datagen.generate(template, argv.format, argv.iterations) - .on('data', (d) => { console.log(d) }) + .on('data', (d) => { + if (argv.format === 'json' && argv.pretty) { + console.log(JSON.stringify(JSON.parse(d), null, 2)) + } else { + console.log(d) + } + }) .on('end', (d) => { }) }).on('error', (e) => { die(e, 2) diff --git a/package-lock.json b/package-lock.json index 1f9baf5..0b2e4f7 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "datamaker", - "version": "0.7.0", + "version": "0.8.0", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index e286842..9d399bd 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "datamaker", - "version": "0.7.0", + "version": "0.8.0", "description": "Sample data generator - command-line utility and library", "main": "index.js", "scripts": {