Skip to content

Commit

Permalink
Fix code smell
Browse files Browse the repository at this point in the history
  • Loading branch information
baloo42 committed Oct 10, 2024
1 parent f952069 commit f00d5c8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ static CommandLine createCommandLine() {

static CommandLine createCommandLine(CRDGeneratorCLI crdGeneratorCLI) {
return new CommandLine(crdGeneratorCLI)
.setExecutionExceptionHandler(new CRDGeneratorExecutionExceptionHandler(crdGeneratorCLI));
.setExecutionExceptionHandler(new CRDGeneratorExecutionExceptionHandler(crdGeneratorCLI::getDiagText));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,16 @@
import org.slf4j.LoggerFactory;
import picocli.CommandLine;

import java.util.function.Supplier;

class CRDGeneratorExecutionExceptionHandler implements CommandLine.IExecutionExceptionHandler {

private static final Logger log = LoggerFactory.getLogger(CRDGeneratorExecutionExceptionHandler.class);

private final CRDGeneratorCLI crdGeneratorCLI;
private final Supplier<String> diagTextSupplier;

CRDGeneratorExecutionExceptionHandler(CRDGeneratorCLI crdGeneratorCLI) {
this.crdGeneratorCLI = crdGeneratorCLI;
CRDGeneratorExecutionExceptionHandler(Supplier<String> diagTextSupplier) {
this.diagTextSupplier = diagTextSupplier;
}

@Override
Expand All @@ -44,7 +46,7 @@ public int handleExecutionException(
"Check the list of classpath elements and add further JAR archives " +
"or directories containing required classes " +
"e.g. with `-cp my-dep.jar` or `-cp target/classes/`.");
commandLine.getErr().print(crdGeneratorCLI.getDiagText());
commandLine.getErr().print(diagTextSupplier.get());
return CRDGeneratorExitCode.CR_CLASS_LOADING;
}

Expand All @@ -53,12 +55,12 @@ public int handleExecutionException(
commandLine.getErr().println("Check JAR files and directories considered to be scanned " +
"as well as your filters. At least one Custom Resource class " +
"must be retained after filtering.");
commandLine.getErr().print(crdGeneratorCLI.getDiagText());
commandLine.getErr().print(diagTextSupplier.get());
return CRDGeneratorExitCode.NO_CR_CLASSES_RETAINED;
}

if (log.isDebugEnabled()) {
commandLine.getErr().println(crdGeneratorCLI.getDiagText());
commandLine.getErr().println(diagTextSupplier.get());
}

log.trace(ex.getMessage(), ex);
Expand Down

0 comments on commit f00d5c8

Please sign in to comment.