mirror of
https://github.com/sbrl/terrain50-cli.git
synced 2024-11-26 07:33:00 +00:00
Add Terrain50.ParseStream support
This commit is contained in:
parent
a247768b8a
commit
85ba35646f
4 changed files with 56 additions and 24 deletions
29
package-lock.json
generated
29
package-lock.json
generated
|
@ -1,18 +1,18 @@
|
||||||
{
|
{
|
||||||
"name": "terrain50-cli",
|
"name": "terrain50-cli",
|
||||||
"version": "1.0.0",
|
"version": "1.0.1",
|
||||||
"lockfileVersion": 1,
|
"lockfileVersion": 1,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@iarna/toml": {
|
"@iarna/toml": {
|
||||||
"version": "2.2.3",
|
"version": "2.2.5",
|
||||||
"resolved": "https://registry.npmjs.org/@iarna/toml/-/toml-2.2.3.tgz",
|
"resolved": "https://registry.npmjs.org/@iarna/toml/-/toml-2.2.5.tgz",
|
||||||
"integrity": "sha512-FmuxfCuolpLl0AnQ2NHSzoUKWEJDFl63qXjzdoWBVyFCXzMGm1spBzk7LeHNoVCiWCF7mRVms9e6jEV9+MoPbg=="
|
"integrity": "sha512-trnsAYxU3xnS1gPHPyU961coFyLkh4gAD/0zQ5mymY4yOZ+CYvsPqUbOFSw0aDM4y0tV7tiFxL/1XfXPNC6IPg=="
|
||||||
},
|
},
|
||||||
"applause-cli": {
|
"applause-cli": {
|
||||||
"version": "1.2.0",
|
"version": "1.2.2",
|
||||||
"resolved": "https://registry.npmjs.org/applause-cli/-/applause-cli-1.2.0.tgz",
|
"resolved": "https://registry.npmjs.org/applause-cli/-/applause-cli-1.2.2.tgz",
|
||||||
"integrity": "sha512-JPCHkBzaghitUPYWK4Jm6YNUklJIBjhlvzU3WLswjvjolMyQN8WVWR8qrGmMbs1skej2p/ZINisZVVvmuEFkog=="
|
"integrity": "sha512-JB5PHttRc5bQhEIw3Hki4NPsIQbU9ChzVBNLpRnEwitMLYWors0Sy8wknERwPPuixAXakaHBw18Jm+ofwItzbg=="
|
||||||
},
|
},
|
||||||
"arr-flatten": {
|
"arr-flatten": {
|
||||||
"version": "1.1.0",
|
"version": "1.1.0",
|
||||||
|
@ -279,12 +279,12 @@
|
||||||
"integrity": "sha512-NCrCHhWmnQklfH4MtJMRjZ2a8c80qXeMlQMv2uVp9ISJMTt562SbGd6n2oq0PaPgKm7Z6pL9E2UlLIhC+SHL3w=="
|
"integrity": "sha512-NCrCHhWmnQklfH4MtJMRjZ2a8c80qXeMlQMv2uVp9ISJMTt562SbGd6n2oq0PaPgKm7Z6pL9E2UlLIhC+SHL3w=="
|
||||||
},
|
},
|
||||||
"proj4": {
|
"proj4": {
|
||||||
"version": "2.6.0",
|
"version": "2.6.1",
|
||||||
"resolved": "https://registry.npmjs.org/proj4/-/proj4-2.6.0.tgz",
|
"resolved": "https://registry.npmjs.org/proj4/-/proj4-2.6.1.tgz",
|
||||||
"integrity": "sha512-ll2WyehUFOyzEZtN8hAiOTmZpuDCN5V+4A/HjhPbhlwVwlsFKnIHSZ3l3uhzgDndHjoL2MyERFGe9VmXN4rYUg==",
|
"integrity": "sha512-RP5EcrfrLcARy+Zjjz1wIeqZzZdPtQNl685asHcwdU/MQ/dvydmf1XWM4mgok6wPaNsXZ8IFrM4qadO3g46PiQ==",
|
||||||
"requires": {
|
"requires": {
|
||||||
"mgrs": "1.0.0",
|
"mgrs": "1.0.0",
|
||||||
"wkt-parser": "^1.2.0"
|
"wkt-parser": "^1.2.4"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"pxls": {
|
"pxls": {
|
||||||
|
@ -338,10 +338,11 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"terrain50": {
|
"terrain50": {
|
||||||
"version": "1.3.0",
|
"version": "1.4.0",
|
||||||
"resolved": "https://registry.npmjs.org/terrain50/-/terrain50-1.3.0.tgz",
|
"resolved": "https://registry.npmjs.org/terrain50/-/terrain50-1.4.0.tgz",
|
||||||
"integrity": "sha512-BkQMAY6W67FsE1yWr24yHBhd46lQCdwON1/pMkZsLTWl1EYiaSPCNu+QCO4GV/7E8b9IXgiPUQpOqtiA5sZ6BQ==",
|
"integrity": "sha512-N+2Im3s4LUhB5Atrsk7TKuJ7ty6maL3dz/jb+jAF48X4yK/YY6Fi4GSaCp2xx2+9F9YBMrzeJA6iDzQpMDr91A==",
|
||||||
"requires": {
|
"requires": {
|
||||||
|
"nexline": "^1.2.0",
|
||||||
"nnng": "^1.0.0"
|
"nnng": "^1.0.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
|
@ -32,12 +32,12 @@
|
||||||
],
|
],
|
||||||
"homepage": "https://github.com/sbrl/terrain50-cli#readme",
|
"homepage": "https://github.com/sbrl/terrain50-cli#readme",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@iarna/toml": "^2.2.3",
|
"@iarna/toml": "^2.2.5",
|
||||||
"applause-cli": "^1.2.0",
|
"applause-cli": "^1.2.2",
|
||||||
"chroma-js": "^2.1.0",
|
"chroma-js": "^2.1.0",
|
||||||
"image-encode": "^1.3.0",
|
"image-encode": "^1.3.0",
|
||||||
"nexline": "^1.2.0",
|
"nexline": "^1.2.0",
|
||||||
"terrain50": "^1.3.0"
|
"terrain50": "^1.4.0"
|
||||||
},
|
},
|
||||||
"bin": {
|
"bin": {
|
||||||
"terrain50": "./src/index.mjs"
|
"terrain50": "./src/index.mjs"
|
||||||
|
|
|
@ -5,12 +5,38 @@ import fs from 'fs';
|
||||||
import a from '../../Helpers/Ansi.mjs';
|
import a from '../../Helpers/Ansi.mjs';
|
||||||
import Terrain50 from 'terrain50';
|
import Terrain50 from 'terrain50';
|
||||||
|
|
||||||
export default async function(_settings) {
|
export default async function(settings) {
|
||||||
|
switch(settings.cli.mode) {
|
||||||
|
case "validate":
|
||||||
// Read stdin into a string - ref https://stackoverflow.com/a/56012724/1460422
|
// Read stdin into a string - ref https://stackoverflow.com/a/56012724/1460422
|
||||||
let source = fs.readFileSync(0, 'utf-8');
|
let source = fs.readFileSync(0, 'utf-8');
|
||||||
|
|
||||||
let errors = Terrain50.Validate(source);
|
let errors = Terrain50.Validate(source);
|
||||||
|
display_errors(errors);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "stream":
|
||||||
|
let i = 0;
|
||||||
|
for await (let next of Terrain50.ParseStream(process.stdin)) {
|
||||||
|
console.log(`>>> Item ${i} <<<`);
|
||||||
|
display_errors(next.validate());
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
console.error(`${a.fred}${a.hicol}Error: Mode '${settings.cli.mode}' was not recognised. Possible modes: validate (the default), stream.${a.reset}`);
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Displays the errors returned by a Terrain50 validation function.
|
||||||
|
* (e.g. `Terrain50.Validate(str)`, or `obj.validate()`)
|
||||||
|
* @param {[type]} errors [description]
|
||||||
|
* @return {[type]} [description]
|
||||||
|
*/
|
||||||
|
function display_errors(errors) {
|
||||||
if(errors.length > 0) {
|
if(errors.length > 0) {
|
||||||
for(let error of errors) {
|
for(let error of errors) {
|
||||||
switch(error.level) {
|
switch(error.level) {
|
||||||
|
@ -30,5 +56,4 @@ export default async function(_settings) {
|
||||||
else {
|
else {
|
||||||
console.log(`${a.fgreen}Validation completed successfully - no issues detected :D${a.reset}`);
|
console.log(`${a.fgreen}Validation completed successfully - no issues detected :D${a.reset}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1 +1,7 @@
|
||||||
description = "Read the Terrain50 file on stdin, validate it, and display any errors found"
|
description = "Read the Terrain50 file on stdin, validate it, and display any errors found"
|
||||||
|
|
||||||
|
[[arguments]]
|
||||||
|
name = "mode"
|
||||||
|
description = "The mode to operate in. Possible values: validate (default), stream. If stream, then validation will be done on individual items after parsing (otherwise validation is done during parsing, which catches more errors)"
|
||||||
|
default_value = "validate"
|
||||||
|
type = "string"
|
||||||
|
|
Loading…
Reference in a new issue