diff --git a/bin/land2geo b/bin/land2geo index 702eb8a..197ab55 100755 --- a/bin/land2geo +++ b/bin/land2geo @@ -1,6 +1,7 @@ #!/usr/bin/env node const landxml = require('../bundles/landxml.node.dev'); +const fs = require('fs'); const argv = require('yargs') .scriptName("land2geo") @@ -25,13 +26,23 @@ const argv = require('yargs') describe: 'the source coordinates projection to use for the LandXML file', type: 'string' }) + .option('o', { + alias: 'output', + describe: 'the path to the output file. default to stdout', + type: 'string' + }) ; }, handler: argv => { const converter = new landxml.Converter(); converter.toGeoJSON(argv.file, { projection: argv.projection }) .then(geojson => { - console.log(JSON.stringify(geojson, null, 2)); + const data = JSON.stringify(geojson, null, 2); + if (argv.output) { + fs.writeFileSync(argv.output, data); + } else { + console.log(data); + } }) .catch(err => { console.error(err);