Skip to content

Commit

Permalink
Add an option to silence warnings about duplicate flags
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-mgalindo committed Jun 20, 2024
1 parent 8c9b0b0 commit b2373ac
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,7 @@ DetailedExitCode parseOptions(List<String> args, ExtendedEventHandler eventHandl
// to improve the user experience, but not required for safety or correctness.
optionsPolicyEnforcer.enforce(optionsParser, commandAnnotation.name());
// Print warnings for odd options usage
for (String warning : optionsParser.getWarnings()) {
for (String warning : getFilteredWarnings(optionsParser)) {
eventHandler.handle(Event.warn(warning));
}
CommonCommandOptions commonOptions = optionsParser.getOptions(CommonCommandOptions.class);
Expand Down Expand Up @@ -704,4 +704,20 @@ private static void partitionCommandLineArgs(
}
}
}

public static ImmutableList<String> getFilteredWarnings(OptionsParser parser) {
CommonCommandOptions commonOptions = parser.getOptions(CommonCommandOptions.class);
Preconditions.checkNotNull(commonOptions,
"getWarnings can only be called after options parsing");

ImmutableList.Builder<String> warnings = ImmutableList.<String>builder();
for (String warning : parser.getWarnings()) {
if (!commonOptions.reportDuplicateOptionsAndConfigs && warning.contains(
"was expanded to from both")) {
continue;
}
warnings.add(warning);
}
return warnings.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -532,6 +532,14 @@ public String getTypeDescription() {
+ " them.")
public boolean heuristicallyDropNodes;

@Option(
name = "snowflake_report_duplicate_options_and_configs",
defaultValue = "true",
documentationCategory = OptionDocumentationCategory.LOGGING,
effectTags = {OptionEffectTag.TERMINAL_OUTPUT},
help = "If enabled, reports flags and configs that were expanded multiple times as warnings.")
public boolean reportDuplicateOptionsAndConfigs;

/** The option converter to check that the user can only specify legal profiler tasks. */
public static class ProfilerTaskConverter extends EnumConverter<ProfilerTask> {
public ProfilerTaskConverter() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,11 @@ static void expandConfigOptions(

// At this point, we've expanded everything, identify duplicates, if any, to warn about
// re-application.
List<String> configs = optionsParser.getOptions(CommonCommandOptions.class).configs;
CommonCommandOptions commonOptions = optionsParser.getOptions(CommonCommandOptions.class);
if (!commonOptions.reportDuplicateOptionsAndConfigs) {
return;
}
List<String> configs = commonOptions.configs;
Set<String> configSet = new HashSet<>();
LinkedHashSet<String> duplicateConfigs = new LinkedHashSet<>();
for (String configValue : configs) {
Expand Down

0 comments on commit b2373ac

Please sign in to comment.