Repository: apache/kafka
File: tools/src/main/java/org/apache/kafka/tools/VerifiableConsumer.java (Java)

Code before:
                .dest("commandConfigFile")
                .help("Consumer config properties file.");

        return parser;
    }

    public static VerifiableConsumer createFromArgs(ArgumentParser parser, String[] args) throws ArgumentParserException {
        Namespace res = parser.parseArgs(args);

        boolean useAutoCommit = res.getBoolean("useAutoCommit");
        String configFile = res.getString("consumer.config");
        String commandConfigFile = res.getString("command-config");
        String brokerHostAndPort = res.getString("bootstrapServer");

        Properties consumerProps = new Properties();
        if (configFile != null && commandConfigFile != null) {
            throw new ArgumentParserException("Options --consumer.config and --command-config are mutually exclusive.", parser);
        }
        if (configFile != null) {
            try {
                consumerProps.putAll(Utils.loadProps(configFile));
            } catch (IOException e) {
                throw new ArgumentParserException(e.getMessage(), parser);
            }
        }
        if (res.getString(commandConfigFile) != null) {
            try {
                consumerProps.putAll(Utils.loadProps(res.getString(commandConfigFile)));
            } catch (IOException e) {
                throw new ArgumentParserException(e.getMessage(), parser);
            }
        }

        GroupProtocol groupProtocol = GroupProtocol.of(res.getString("groupProtocol"));
        consumerProps.put(ConsumerConfig.GROUP_PROTOCOL_CONFIG, groupProtocol.name());

        // 3.7.0 includes support for KIP-848 which introduced a new implementation of the consumer group protocol.
        // The two implementations use slightly different configuration, hence these arguments are conditional.
        //
        // See the Python class/method VerifiableConsumer.start_cmd() in verifiable_consumer.py for how the
        // command line arguments are passed in by the system test framework.
        if (groupProtocol == GroupProtocol.CONSUMER) {
            String groupRemoteAssignor = res.getString("groupRemoteAssignor");

            if (groupRemoteAssignor != null)
                consumerProps.put(ConsumerConfig.GROUP_REMOTE_ASSIGNOR_CONFIG, groupRemoteAssignor);
        } else {
            // This means we're using the CLASSIC consumer group protocol.
            consumerProps.put(ConsumerConfig.PARTITION_ASSIGNMENT_STRATEGY_CONFIG, res.getString("assignmentStrategy"));
        }


Review comment (refactor):
Can't you just use `if (commandConfigFile != null)` here? And also simplify the `loadProps` line accordingly?

Code after:
                .dest("commandConfigFile")
                .help("Config properties file (config options shared with command line parameters will be overridden).");

        return parser;
    }

    public static VerifiableConsumer createFromArgs(ArgumentParser parser, String[] args) throws ArgumentParserException {
        Namespace res = parser.parseArgs(args);

        boolean useAutoCommit = res.getBoolean("useAutoCommit");
        String configFile = res.getString("consumer.config");
        String commandConfigFile = res.getString("commandConfigFile");
        String brokerHostAndPort = res.getString("bootstrapServer");

        Properties consumerProps = new Properties();
        if (configFile != null && commandConfigFile != null) {
            throw new ArgumentParserException("Options --consumer.config and --command-config are mutually exclusive.", parser);
        }
        if (configFile != null) {
            System.out.println("Option --consumer.config has been deprecated and will be removed in a future version. Use --command-config instead.");
            try {
                consumerProps.putAll(Utils.loadProps(configFile));
            } catch (IOException e) {
                throw new ArgumentParserException(e.getMessage(), parser);
            }
        }
        if (commandConfigFile != null) {
            try {
                consumerProps.putAll(Utils.loadProps(res.getString(commandConfigFile)));
            } catch (IOException e) {
                throw new ArgumentParserException(e.getMessage(), parser);
            }
        }

        GroupProtocol groupProtocol = GroupProtocol.of(res.getString("groupProtocol"));
        consumerProps.put(ConsumerConfig.GROUP_PROTOCOL_CONFIG, groupProtocol.name());

        // 3.7.0 includes support for KIP-848 which introduced a new implementation of the consumer group protocol.
        // The two implementations use slightly different configuration, hence these arguments are conditional.
        //
        // See the Python class/method VerifiableConsumer.start_cmd() in verifiable_consumer.py for how the
        // command line arguments are passed in by the system test framework.
        if (groupProtocol == GroupProtocol.CONSUMER) {
            String groupRemoteAssignor = res.getString("groupRemoteAssignor");

            if (groupRemoteAssignor != null)
                consumerProps.put(ConsumerConfig.GROUP_REMOTE_ASSIGNOR_CONFIG, groupRemoteAssignor);
        } else {
            // This means we're using the CLASSIC consumer group protocol.
            consumerProps.put(ConsumerConfig.PARTITION_ASSIGNMENT_STRATEGY_CONFIG, res.getString("assignmentStrategy"));
        }