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

Improve CLI validation output #1695

Merged
merged 3 commits into from
Mar 30, 2023
Merged

Improve CLI validation output #1695

merged 3 commits into from
Mar 30, 2023

Conversation

mtdowling
Copy link
Member

@mtdowling mtdowling commented Mar 28, 2023

This commit adds more colorful and easier to scan validation output for the CLI.

To support this change, I needed to introduce a new validation event formatter that uses ANSI codes. Updating the existing formatter would have added a ton of composition to it, making it hard to understand.

When breaking out a new validation event formatter, I noticed some duplicate code in handling: 1) creating a human-readable filename 2) loading a line of text from a source location.

To account for (1), I added getHumanReadableFilename() to ValidationEvent.

To account for (2), I created a new abstraction for grabbing source context from a SourceLocation.

I ended up needing an abstraction for emitting lots of content that's wrapped in ANSI color escapes, and I didn't want to add escapes over and over or have to buffer intermediate output to a string, so I added a method for wrapping a Consumer that handles adding ANSI styles before and after the consumer is called.

Style was updated to an interface in case we ever want to support theming and use HEX code colors.

Issue #, if available:

Description of changes:

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@mtdowling mtdowling force-pushed the improve-cli-validation-output branch 8 times, most recently from 284c557 to 2a95106 Compare March 29, 2023 16:29
This commit adds more colorful and easier to scan validation output
for the CLI.

To support this change, I needed to introduce a new validation event
formatter that uses ANSI codes. Updating the existing formatter would
have added a ton of composition to it, making it hard to understand.

When breaking out a new validation event formatter, I noticed some
duplicate code in handling: 1) creating a human-readable filename
2) loading a line of text from a source location.

To account for (1), I added getHumanReadableFilename() to
ValidationEvent.

To account for (2), I created a new abstraction for grabbing source
context from a SourceLocation.

I ended up needing an abstraction for emitting lots of content that's
wrapped in ANSI color escapes, and I didn't want to add escapes over
and over or have to buffer intermediate output to a string, so I added
a method for wrapping a Consumer<Appendable> that handles adding
ANSI styles before and after the consumer is called.

Style was updated to an interface in case we ever want to support
theming and use HEX code colors.
@mtdowling mtdowling force-pushed the improve-cli-validation-output branch from 2a95106 to 5272350 Compare March 29, 2023 22:16
@mtdowling mtdowling marked this pull request as ready for review March 29, 2023 22:26
@mtdowling mtdowling requested a review from a team as a code owner March 29, 2023 22:26
The select command doesn't need to perform validation or show
validation summary information. This commit updates the select
command to only show validation information if the model can't
be loaded.
If a source file location can't be read (it's invalid, transient
error, etc.), then don't fail to pretty print the issue. Instead
report the error.
@mtdowling mtdowling merged commit 858c55f into main Mar 30, 2023
@mtdowling mtdowling deleted the improve-cli-validation-output branch April 7, 2023 03:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants