1
0
Fork 0
mirror of https://github.com/sbrl/terrain50-cli.git synced 2024-11-26 07:33:00 +00:00

Add --quiet argument to validate subcommand

This commit is contained in:
Starbeamrainbowlabs 2020-10-02 18:40:19 +01:00
parent 27a0997f65
commit e104da450c
Signed by: sbrl
GPG key ID: 1BE5172E637709C2
3 changed files with 19 additions and 7 deletions

View file

@ -14,6 +14,11 @@ npm install --save terrain50-cli
----- -----
## v1.6
- Add new `split` subcommand
- `validate` subcommand: Add new `--quiet` argument
## v1.5 ## v1.5
- Update dependencies - Update dependencies
- Add new `analyse-frequencies` subcommand - Add new `analyse-frequencies` subcommand

View file

@ -12,15 +12,16 @@ export default async function(settings) {
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); display_errors(errors, settings.cli.quiet);
break; break;
case "stream": case "stream":
let i = 0, ok = 0, failed = 0; let i = 0, ok = 0, failed = 0;
for await (let next of Terrain50.ParseStream(process.stdin, settings.cli.use_regex ? /\s+/ : " ")) { for await (let next of Terrain50.ParseStream(process.stdin, settings.cli.use_regex ? /\s+/ : " ")) {
console.log(`>>> Item ${i} <<<`); if(!settings.cli.quiet) console.log(`>>> Item ${i} <<<`);
let result = next.validate(); let result = next.validate();
display_errors(result); if(settings.cli.quiet && result.length > 0) console.log(`>>> Item ${i} <<<`);
display_errors(result, settings.cli.quiet);
if(result.length > 0) failed++; else ok++; if(result.length > 0) failed++; else ok++;
i++; i++;
} }
@ -36,10 +37,10 @@ export default async function(settings) {
/** /**
* Displays the errors returned by a Terrain50 validation function. * Displays the errors returned by a Terrain50 validation function.
* (e.g. `Terrain50.Validate(str)`, or `obj.validate()`) * (e.g. `Terrain50.Validate(str)`, or `obj.validate()`)
* @param {[type]} errors [description] * @param {Terrain50ValidationMessage[]} errors The list of validation errors to display.
* @return {[type]} [description] * @param {bool} [quiet=false] Whether to avoid printing anything if the list of errors is empty
*/ */
function display_errors(errors) { function display_errors(errors, quiet = false) {
if(errors.length > 0) { if(errors.length > 0) {
for(let error of errors) { for(let error of errors) {
switch(error.level) { switch(error.level) {
@ -56,7 +57,7 @@ function display_errors(errors) {
} }
process.exit(1); process.exit(1);
} }
else { else if(!quiet) {
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}`);
} }
} }

View file

@ -11,3 +11,9 @@ name = "use-regex"
description = "When in stream mode only, setting this flag causes a regular expression to be used when parsing input data (otherwise it is assumed a single space separates elements on a line). Makes the parser more tolerant, but less performant." description = "When in stream mode only, setting this flag causes a regular expression to be used when parsing input data (otherwise it is assumed a single space separates elements on a line). Makes the parser more tolerant, but less performant."
default_value = false default_value = false
type = "boolean" type = "boolean"
[[arguments]]
name = "quiet"
description = "Don't print validation individual success messages, only errors"
default_value = false
type = "boolean"