#!/usr/bin/env node

var numerify = require('./'),
    opt = require('optimist')
        .usage('Usage: $0 FILE')
        .boolean('r').describe('r', 'recursive. Will recusively walk through nested objects and arrays')
        .boolean('version').describe('version','display software version')
        .boolean('help').describe('help','print this help message'),
    argv = opt.argv,
    fs = require('fs'),
    concat = require('concat-stream'),
    pack = require('./package.json');

if (argv.help) {
    return opt.showHelp();
}
if (argv.version) {
    process.stdout.write(pack.version+'\n');
    return;
}

(argv._.length ? fs.createReadStream(argv._[0]) : process.stdin).pipe(concat(convert));

function convert(data) {
    process.stdout.write(
        JSON.stringify(
            numerify(
                JSON.parse(data),
                argv.r
            ),
            null, 2
        )
    );
    process.stdout.on('error', function() {});
}
