Skip to content

Commit 876365f

Browse files
committed
Use non-deprecated help formatter from Commons CLI
1 parent b1ae7c7 commit 876365f

File tree

1 file changed

+31
-9
lines changed

1 file changed

+31
-9
lines changed

src/main/java/com/rabbitmq/perf/PerfTest.java

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,15 @@
7575
import java.util.stream.Collectors;
7676
import javax.net.ssl.SSLContext;
7777
import javax.net.ssl.TrustManager;
78-
import org.apache.commons.cli.*;
78+
import org.apache.commons.cli.CommandLine;
79+
import org.apache.commons.cli.CommandLineParser;
80+
import org.apache.commons.cli.DefaultParser;
81+
import org.apache.commons.cli.MissingArgumentException;
82+
import org.apache.commons.cli.Option;
83+
import org.apache.commons.cli.Options;
84+
import org.apache.commons.cli.ParseException;
85+
import org.apache.commons.cli.help.HelpFormatter;
86+
import org.apache.commons.cli.help.OptionFormatter;
7987
import org.slf4j.Logger;
8088
import org.slf4j.LoggerFactory;
8189

@@ -970,13 +978,20 @@ private static boolean isPropertyTlsRelated(String propertyName) {
970978
}
971979

972980
private static void usage(Options options) {
973-
HelpFormatter formatter = new HelpFormatter();
974-
formatter.printHelp("<program>", options);
981+
HelpFormatter formatter = HelpFormatter.builder().setShowSince(false).get();
982+
try {
983+
formatter.printHelp("perf-test", "", options, "", true);
984+
} catch (IOException e) {
985+
throw new RuntimeException(e);
986+
}
975987
}
976988

977989
private static void usageWithEnvironmentVariables(Options options) {
978-
HelpFormatter formatter = new HelpFormatter();
979-
formatter.setOptPrefix("");
990+
HelpFormatter formatter =
991+
HelpFormatter.builder()
992+
.setShowSince(false)
993+
.setOptionFormatBuilder(OptionFormatter.builder().setOptPrefix(""))
994+
.get();
980995
Options envOptions = new Options();
981996
forEach(
982997
options,
@@ -992,10 +1007,17 @@ private static void usageWithEnvironmentVariables(Options options) {
9921007
option.getDescription());
9931008
}
9941009
});
995-
formatter.printHelp(
996-
"<program>. For multi-value options, separate values "
997-
+ "with commas, e.g. VARIABLE_RATE='100:60,1000:10,500:15'",
998-
envOptions);
1010+
try {
1011+
formatter.printHelp(
1012+
"perf-test",
1013+
" For multi-value options, separate values "
1014+
+ "with commas, e.g. VARIABLE_RATE='100:60,1000:10,500:15'",
1015+
envOptions,
1016+
"",
1017+
true);
1018+
} catch (IOException e) {
1019+
throw new RuntimeException(e);
1020+
}
9991021
}
10001022

10011023
static CommandLineParser getParser() {

0 commit comments

Comments
 (0)