From ca77c019457bee6b9878fb594475ac629b6e3ff2 Mon Sep 17 00:00:00 2001 From: William Petit Date: Wed, 30 Jun 2021 15:18:47 +0200 Subject: [PATCH] Save output to file in land2geo --- bin/land2geo | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) 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);