private long parseOffset() {
        if (options.has(offsetOpt)) {
            switch (options.valueOf(offsetOpt).toLowerCase(Locale.ROOT)) {
                case "earliest":
                    return ListOffsetsRequest.EARLIEST_TIMESTAMP;
                case "latest":
                    return ListOffsetsRequest.LATEST_TIMESTAMP;
                default:
                    String offsetString = options.valueOf(offsetOpt);
                    try {
                        long offset = Long.parseLong(offsetString);
                        if (offset < 0) {
                            invalidOffset(offsetString);
                        }
                        return offset;
                    } catch (NumberFormatException nfe) {
                        invalidOffset(offsetString);
                    }
            }
        } else if (fromBeginning()) {
            return ListOffsetsRequest.EARLIEST_TIMESTAMP;
        }
        return ListOffsetsRequest.LATEST_TIMESTAMP;
    }
@Test
    public void testParseOffset() throws Exception {
        Exit.setExitProcedure((code, message) -> {
            throw new IllegalArgumentException(message);
        });

        try {
            final String[] badOffset = new String[]{
                "--bootstrap-server", "localhost:9092",
                "--topic", "test",
                "--partition", "0",
                "--offset", "bad"
            };
            assertThrows(IllegalArgumentException.class, () -> new ConsoleConsumerOptions(badOffset));

            final String[] negativeOffset = new String[]{
                "--bootstrap-server", "localhost:9092",
                "--topic", "test",
                "--partition", "0",
                "--offset", "-100"
            };
            assertThrows(IllegalArgumentException.class, () -> new ConsoleConsumerOptions(negativeOffset));

            final String[] earliestOffset = new String[]{
                "--bootstrap-server", "localhost:9092",
                "--topic", "test",
                "--partition", "0",
                "--offset", "earliest"
            };
            ConsoleConsumerOptions config = new ConsoleConsumerOptions(earliestOffset);
            assertEquals(ListOffsetsRequest.EARLIEST_TIMESTAMP, config.offsetArg());
        } finally {
            Exit.resetExitProcedure();
        }
    }