mirror of https://github.com/apache/kafka.git
KAFKA-16408 kafka-get-offsets / GetOffsetShell doesn't handle --version or --help (#15583)
Reviewers: Chia-Ping Tsai <chia7712@gmail.com>
This commit is contained in:
parent
bf9a27fefd
commit
0434c29e58
|
@ -59,6 +59,7 @@ import java.util.regex.Pattern;
|
|||
import java.util.stream.Collectors;
|
||||
|
||||
public class GetOffsetShell {
|
||||
static final String USAGE_TEXT = "An interactive shell for getting topic-partition offsets.";
|
||||
private static final Pattern TOPIC_PARTITION_PATTERN = Pattern.compile("([^:,]*)(?::(?:([0-9]*)|(?:([0-9]*)-([0-9]*))))?");
|
||||
|
||||
public static void main(String... args) {
|
||||
|
@ -142,7 +143,7 @@ public class GetOffsetShell {
|
|||
excludeInternalTopicsOpt = parser.accepts("exclude-internal-topics", "By default, internal topics are included. If specified, internal topics are excluded.");
|
||||
|
||||
if (args.length == 0) {
|
||||
CommandLineUtils.printUsageAndExit(parser, "An interactive shell for getting topic-partition offsets.");
|
||||
CommandLineUtils.printUsageAndExit(parser, USAGE_TEXT);
|
||||
}
|
||||
|
||||
try {
|
||||
|
@ -157,6 +158,8 @@ public class GetOffsetShell {
|
|||
effectiveBrokerListOpt = brokerListOpt;
|
||||
}
|
||||
|
||||
CommandLineUtils.maybePrintHelpOrVersion(this, USAGE_TEXT);
|
||||
|
||||
CommandLineUtils.checkRequiredArgs(parser, options, effectiveBrokerListOpt);
|
||||
|
||||
String brokerList = options.valueOf(effectiveBrokerListOpt);
|
||||
|
|
|
@ -29,6 +29,7 @@ import org.apache.kafka.clients.producer.KafkaProducer;
|
|||
import org.apache.kafka.clients.producer.ProducerConfig;
|
||||
import org.apache.kafka.clients.producer.ProducerRecord;
|
||||
import org.apache.kafka.common.serialization.StringSerializer;
|
||||
import org.apache.kafka.common.utils.AppInfoParser;
|
||||
import org.apache.kafka.common.utils.Exit;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Tag;
|
||||
|
@ -317,6 +318,18 @@ public class GetOffsetShellTest {
|
|||
assertExitCodeIsOne("--topic-partitions", "__consumer_offsets", "--partitions", "0");
|
||||
}
|
||||
|
||||
@ClusterTest
|
||||
public void testPrintHelp() {
|
||||
String out = ToolsTestUtils.captureStandardErr(() -> GetOffsetShell.mainNoExit("--help"));
|
||||
assertTrue(out.startsWith(GetOffsetShell.USAGE_TEXT));
|
||||
}
|
||||
|
||||
@ClusterTest
|
||||
public void testPrintVersion() {
|
||||
String out = ToolsTestUtils.captureStandardOut(() -> GetOffsetShell.mainNoExit("--version"));
|
||||
assertEquals(AppInfoParser.getVersion(), out);
|
||||
}
|
||||
|
||||
private void assertExitCodeIsOne(String... args) {
|
||||
final int[] exitStatus = new int[1];
|
||||
|
||||
|
|
Loading…
Reference in New Issue