Skip to content

Commit 6a1cdf8

Browse files
authored
MINOR: Refactor CLI tools to use CommandLineUtils#maybePrintHelpOrVersion (#20469)
Refactor help and version handling in command-line tools by replacing duplicate code with `CommandLineUtils#maybePrintHelpOrVersion`. Reviewers: TengYao Chi <[email protected]>, Ken Huang <[email protected]>, Jhen-Yung Hsu <[email protected]>, Chia-Ping Tsai <[email protected]>
1 parent 29b940b commit 6a1cdf8

File tree

3 files changed

+4
-20
lines changed

3 files changed

+4
-20
lines changed

tools/src/main/java/org/apache/kafka/tools/JmxTool.java

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -66,14 +66,7 @@ public class JmxTool {
6666
public static void main(String[] args) {
6767
try {
6868
JmxToolOptions options = new JmxToolOptions(args);
69-
if (CommandLineUtils.isPrintHelpNeeded(options)) {
70-
CommandLineUtils.printUsageAndExit(options.parser, "Dump JMX values to standard output.");
71-
return;
72-
}
73-
if (CommandLineUtils.isPrintVersionNeeded(options)) {
74-
CommandLineUtils.printVersionAndExit();
75-
return;
76-
}
69+
CommandLineUtils.maybePrintHelpOrVersion(options, "Dump JMX values to standard output.");
7770

7871
Optional<String[]> attributesInclude = options.attributesInclude();
7972
Optional<DateFormat> dateFormat = options.dateFormat();

tools/src/main/java/org/apache/kafka/tools/ReplicaVerificationTool.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -300,12 +300,8 @@ private static class ReplicaVerificationToolOptions extends CommandDefaultOption
300300
.ofType(Long.class)
301301
.defaultsTo(30_000L);
302302
options = parser.parse(args);
303-
if (args.length == 0 || options.has(helpOpt)) {
304-
CommandLineUtils.printUsageAndExit(parser, "Validate that all replicas for a set of topics have the same data.");
305-
}
306-
if (options.has(versionOpt)) {
307-
CommandLineUtils.printVersionAndExit();
308-
}
303+
304+
CommandLineUtils.maybePrintHelpOrVersion(this, "Validate that all replicas for a set of topics have the same data.");
309305
CommandLineUtils.checkRequiredArgs(parser, options, brokerListOpt);
310306
}
311307

tools/src/main/java/org/apache/kafka/tools/StreamsResetter.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -647,12 +647,7 @@ public StreamsResetterOptions(String[] args) {
647647

648648
try {
649649
options = parser.parse(args);
650-
if (CommandLineUtils.isPrintHelpNeeded(this)) {
651-
CommandLineUtils.printUsageAndExit(parser, USAGE);
652-
}
653-
if (CommandLineUtils.isPrintVersionNeeded(this)) {
654-
CommandLineUtils.printVersionAndExit();
655-
}
650+
CommandLineUtils.maybePrintHelpOrVersion(this, USAGE);
656651
CommandLineUtils.checkInvalidArgs(parser, options, toOffsetOption, toDatetimeOption, byDurationOption, toEarliestOption, toLatestOption, fromFileOption, shiftByOption);
657652
CommandLineUtils.checkInvalidArgs(parser, options, toDatetimeOption, toOffsetOption, byDurationOption, toEarliestOption, toLatestOption, fromFileOption, shiftByOption);
658653
CommandLineUtils.checkInvalidArgs(parser, options, byDurationOption, toOffsetOption, toDatetimeOption, toEarliestOption, toLatestOption, fromFileOption, shiftByOption);

0 commit comments

Comments
 (0)