Add CLI with support for validating multiple files #13
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem
The tool does not support validating multiple files at once.
Solution
Introduce a CLI that makes it possible to validate several files at once.
Notes
We first tried to wrap the invocation of this tool in a shell script, calling it once per file we needed to validate. With ~400 files it took ~6m30s to complete which felt too long.
We speculated that the bulk of the time being spent during a single execution was in the
Ajv
schema-validation compile phase. We hacked up a script to validate our suspicion and indeed found it to be true. We were able to validate ~400 files in ~6s; with the schema-validation compile happening once (It looks likeAjv
caches compilation; calling it a second time is pretty fast).The choice to use
minimist
was based on introducing the least number of dependencies.There are two ways to provide files to validate:
We chose not to include a file-finder/globber as we felt that role was best left to other tools. e.g. via shell globbing
validate-entity catalog/**/*.yaml
, or piped inputfind ./catalog/ -name '*.yaml' -or -name '*.yml' | validate-entity -i
Validating several files at once produces a lot of output. To that end, a
quiet
option was introduced to control the verbosity of existing logging statements.Care was taken to not introduce changes to the existing CLI interface which expects a single file to validate.
CLI usage: