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 show/hide validation event filtering to CLI #2127

Merged
merged 1 commit into from
Feb 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ private int runWithClassLoader(SmithyBuildConfig config, Arguments arguments, En
.models(arguments.getPositional())
.validationPrinter(env.stderr())
.validationMode(Validator.Mode.QUIET)
.severity(Severity.DANGER)
.defaultSeverity(Severity.DANGER)
.build();

ModelSerializer serializer = ModelSerializer.builder().build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public String getSummary() {
public int execute(Arguments arguments, Env env) {
arguments.addReceiver(new ConfigOptions());
arguments.addReceiver(new DiscoveryOptions());
arguments.addReceiver(new SeverityOption());
arguments.addReceiver(new ValidatorOptions());
arguments.addReceiver(new BuildOptions());
arguments.addReceiver(new Options());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public String getSummary() {
@Override
public int execute(Arguments arguments, Env env) {
arguments.addReceiver(new ConfigOptions());
arguments.addReceiver(new SeverityOption());
arguments.addReceiver(new ValidatorOptions());
arguments.addReceiver(new BuildOptions());
arguments.addReceiver(new Options());
arguments.getReceiver(BuildOptions.class).noPositionalArguments(true);
Expand Down Expand Up @@ -317,7 +317,7 @@ protected final ModelBuilder createModelBuilder(SmithyBuildConfig config, Argume
.validationPrinter(env.stderr())
// Only report issues that fail the build.
.validationMode(Validator.Mode.QUIET_CORE_ONLY)
.severity(Severity.DANGER);
.defaultSeverity(Severity.DANGER);
}

// Creating a new model is the same for each diff mode.
Expand All @@ -336,7 +336,7 @@ protected final void runDiff(ModelBuilder builder, Env env, Model oldModel, Mode
builder
.titleLabel("DIFF", ColorTheme.DIFF_TITLE)
.validatedResult(new ValidatedResult<>(newModel, events))
.severity(null) // reset so it takes on standard option settings.
.defaultSeverity(null) // reset so it takes on standard option settings.
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ private int run(Arguments arguments, Env env) {
.env(env)
.models(models)
.validationPrinter(env.stderr())
.severity(Severity.DANGER)
.defaultSeverity(Severity.DANGER)
.build();

SmithyBuild smithyBuild = SmithyBuild.create(classLoader)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ final class ModelBuilder {
private List<String> models;
private Command.Env env;
private SmithyBuildConfig config;
private Severity severity;
private Severity defaultSeverity;
private ValidatedResult<Model> validatedResult;
private String titleLabel;
private Style[] titleLabelStyles;
Expand Down Expand Up @@ -94,8 +94,8 @@ public ModelBuilder config(SmithyBuildConfig config) {
return this;
}

public ModelBuilder severity(Severity severity) {
this.severity = severity;
public ModelBuilder defaultSeverity(Severity defaultSeverity) {
this.defaultSeverity = defaultSeverity;
return this;
}

Expand Down Expand Up @@ -123,7 +123,13 @@ public Model build() {

StandardOptions standardOptions = arguments.getReceiver(StandardOptions.class);
BuildOptions buildOptions = arguments.getReceiver(BuildOptions.class);
Severity minSeverity = resolveMinSeverity(standardOptions);

// Resolve validator options and severity.
ValidatorOptions validatorOptions = arguments.hasReceiver(ValidatorOptions.class)
? arguments.getReceiver(ValidatorOptions.class)
: new ValidatorOptions();
resolveMinSeverity(standardOptions, validatorOptions);

ClassLoader classLoader = env.classLoader();
ColorFormatter colors = env.colors();
CliPrinter stderr = env.stderr();
Expand Down Expand Up @@ -176,8 +182,8 @@ public Model build() {

for (ValidationEvent event : sortedEvents) {
// Only log events that are >= --severity. Note that setting --quiet inherently
// configures events to need to be >= DANGER.
if (event.getSeverity().ordinal() >= minSeverity.ordinal()) {
// configures events to need to be >= DANGER. Also filter using --show-validators and --hide-validators.
if (validatorOptions.isVisible(event)) {
validationPrinter.println(formatter.format(event));
}
}
Expand Down Expand Up @@ -274,14 +280,11 @@ private static void discoverModelsWithClasspath(String rawClasspath, ModelAssemb
}

// Determine a default severity if one wasn't given, by inspecting if there is a --severity option.
private Severity resolveMinSeverity(StandardOptions standardOptions) {
if (severity != null) {
return severity;
} else if (arguments.hasReceiver(SeverityOption.class)) {
return arguments.getReceiver(SeverityOption.class).severity(standardOptions);
} else {
return Severity.WARNING;
private Severity resolveMinSeverity(StandardOptions standardOptions, ValidatorOptions validatorOption) {
if (defaultSeverity != null && validatorOption.severity() == null) {
validatorOption.severity(defaultSeverity);
}
return validatorOption.detectAndGetSeverity(standardOptions);
}

static ModelAssembler createModelAssembler(ClassLoader classLoader) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ private int runWithClassLoader(SmithyBuildConfig config, Arguments arguments, En
.models(arguments.getPositional())
.validationPrinter(env.stderr())
.validationMode(Validator.Mode.QUIET_CORE_ONLY)
.severity(Severity.DANGER)
.defaultSeverity(Severity.DANGER)
.build();

Options options = arguments.getReceiver(Options.class);
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public String getSummary() {
public int execute(Arguments arguments, Env env) {
arguments.addReceiver(new ConfigOptions());
arguments.addReceiver(new DiscoveryOptions());
arguments.addReceiver(new SeverityOption());
arguments.addReceiver(new ValidatorOptions());
arguments.addReceiver(new BuildOptions());

CommandAction action = HelpActionWrapper.fromCommand(
Expand Down
Loading
Loading