#! /usr/bin/env node
var JSONStream = require('./')
var lines, args

process.argv.slice(2).forEach(function (e) {
  if(/^(--lines|-l)/.test(e))
    lines = true
  else if(!args) {
    try {
      args = JSON.parse(args)
    } catch (err) {
      args = e
    }
  }
})

process.stdin
  .pipe(JSONStream.parse(args || '*'))
  .pipe(!lines
    ? JSONStream.stringify('[\n', ',\n', '\n]', 2)
    : JSONStream.stringify('', '\n', '\n')
  )
  .pipe(process.stdout)

