Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add CLI with support for validating multiple files #13

Merged
merged 4 commits into from Jul 29, 2021
Merged

Add CLI with support for validating multiple files #13

merged 4 commits into from Jul 29, 2021

Conversation

joncfoo
Copy link
Contributor

@joncfoo joncfoo commented Jul 27, 2021

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 like Ajv 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:

  1. via CLI arguments
  2. via STDIN

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 input find ./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:

❯ node src/index.js -h
Usage: validate-entity [OPTION] [FILE]

Validates Backstage entity definition files.  Files may be specified as
arguments or via STDIN, one per line.

OPTION:
-h  display help
-q  minimal output while validating entities
-i  validate files provided over standard input

@Xantier
Copy link
Contributor

Xantier commented Jul 28, 2021

Thanks @joncfoo! That looks excellent and will be a good addition for this. Could you add few lines to the README file about this as well and I'll merge this in and release new versions.

@Xantier Xantier self-requested a review July 28, 2021 07:26
@Xantier Xantier added this to In progress in Open Source Development (Deprecated) via automation Jul 28, 2021
@joncfoo
Copy link
Contributor Author

joncfoo commented Jul 28, 2021

🎉 I've updated the readme with the usage and examples.

Copy link
Contributor

@Xantier Xantier left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 :shipit:

@Xantier Xantier merged commit cbb64cf into RoadieHQ:main Jul 29, 2021
Open Source Development (Deprecated) automation moved this from In progress to Done Jul 29, 2021
@Xantier
Copy link
Contributor

Xantier commented Jul 29, 2021

Thanks @joncfoo. This is now released as version 0.3.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants