fvaleri commented on code in PR #13122: URL: https://github.com/apache/kafka/pull/13122#discussion_r1071392892
########## tools/src/main/java/org/apache/kafka/tools/LogDirsCommand.java: ########## @@ -0,0 +1,158 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.kafka.tools; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import net.sourceforge.argparse4j.ArgumentParsers; +import net.sourceforge.argparse4j.inf.ArgumentParser; +import net.sourceforge.argparse4j.inf.Namespace; +import org.apache.kafka.clients.admin.Admin; +import org.apache.kafka.clients.admin.AdminClientConfig; +import org.apache.kafka.clients.admin.LogDirDescription; +import org.apache.kafka.common.Node; +import org.apache.kafka.common.utils.Exit; +import org.apache.kafka.common.utils.Utils; + +import java.io.IOException; +import java.util.Arrays; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Properties; +import java.util.Set; +import java.util.concurrent.ExecutionException; +import java.util.stream.Collectors; + +import static net.sourceforge.argparse4j.impl.Arguments.store; + +public class LogDirsCommand { + public static void main(String... args) { + Exit.exit(mainNoExit(args)); + } + + static int mainNoExit(String... args) { + try { + execute(args); + return 0; + } catch (Throwable e) { + System.err.println(e.getMessage()); + System.err.println(Utils.stackTrace(e)); + return 1; + } + } + + static void execute(String[] args) throws ExecutionException, InterruptedException, IOException { + ArgumentParser parser = ArgumentParsers Review Comment: I think that we should keep using `joptsimple` with the `CommandDefaultOptions` abstract class, rather than migrating all commands to `argparse4j`. The vast majority of commands do not use `argparse4j`. Then, the `joptsimple` (current) no-args output is very different: ```sh This tool helps to query log directory usage on the specified brokers. Option Description ------ ----------- --bootstrap-server <String: The server REQUIRED: the server(s) to use for (s) to use for bootstrapping> bootstrapping --broker-list <String: Broker list> The list of brokers to be queried in the form "0,1,2". All brokers in the cluster will be queried if no broker list is specified --command-config <String: Admin client Property file containing configs to be property file> passed to Admin Client. --describe Describe the specified log directories on the specified brokers. --help Print usage information. --topic-list <String: Topic list> The list of topics to be queried in the form "topic1,topic2,topic3". All topics will be queried if no topic list is specified (default: ) --version Display Kafka version. ``` This is the new no-args output with `argparse4j`: ```sh usage: kafka-log-dirs [-h] --bootstrap-server BOOTSTRAP-SERVER [--command-config COMMAND-CONFIG] [--topic-list TOPIC-LIST] [--broker-list BROKER-LIST] kafka-log-dirs: error: argument --bootstrap-server is required ``` @ijuma @mimaison WDYT? -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: jira-unsubscr...@kafka.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org