[MNG-8348] Fix typos in deprecation warning message (#1844)

This commit is contained in:
Guillaume Nodet 2024-10-24 13:51:57 +02:00 committed by GitHub
parent 69c6a3f95b
commit d62ecadb35
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 14 additions and 4 deletions

View File

@ -219,16 +219,22 @@ public abstract class CommonsCliOptions implements Options {
printWriter.accept("Detected deprecated option use in " + source);
for (Option option : cliManager.getUsedDeprecatedOptions()) {
StringBuilder sb = new StringBuilder();
sb.append("The option -").append(option.getOpt());
sb.append("The option ");
if (option.getOpt() != null) {
sb.append("-").append(option.getOpt());
}
if (option.getLongOpt() != null) {
sb.append(",--").append(option.getLongOpt());
if (option.getOpt() != null) {
sb.append(",");
}
sb.append("--").append(option.getLongOpt());
}
sb.append(" is deprecated ");
if (option.getDeprecated().isForRemoval()) {
sb.append("and will be removed in a future version");
}
if (option.getDeprecated().getSince() != null) {
sb.append("since ")
sb.append(" since ")
.append(request.commandName())
.append(" ")
.append(option.getDeprecated().getSince());
@ -415,7 +421,7 @@ public abstract class CommonsCliOptions implements Options {
// We need to eat any quotes surrounding arguments...
String[] cleanArgs = CleanArgument.cleanArgs(args);
DefaultParser parser = DefaultParser.builder()
.setDeprecatedHandler(usedDeprecatedOptions::add)
.setDeprecatedHandler(this::addDeprecatedOption)
.build();
CommandLine commandLine = parser.parse(options, cleanArgs);
// to trigger deprecation handler, so we can report deprecation BEFORE we actually use options
@ -423,6 +429,10 @@ public abstract class CommonsCliOptions implements Options {
return commandLine;
}
protected void addDeprecatedOption(Option option) {
usedDeprecatedOptions.add(option);
}
public org.apache.commons.cli.Options getOptions() {
return options;
}