joshua2519 commented on code in PR #20293:
URL: https://github.com/apache/kafka/pull/20293#discussion_r2374765896


##########
tools/src/main/java/org/apache/kafka/tools/streams/StreamsGroupCommand.java:
##########
@@ -83,27 +85,46 @@ public class StreamsGroupCommand {
     static final String MISSING_COLUMN_VALUE = "-";
 
     public static void main(String[] args) {
-        StreamsGroupCommandOptions opts = new StreamsGroupCommandOptions(args);
+        Exit.exit(execute(args));
+    }
+
+    public static int execute(String[] args) {
+        StreamsGroupCommandOptions opts = null;
+        int exitCode = 0;
         try {
-            opts.checkArgs();
+            opts = new StreamsGroupCommandOptions(args);
+            Objects.requireNonNull(opts).checkArgs();
             // should have exactly one action
             long numberOfActions = Stream.of(
-                opts.listOpt,
-                opts.describeOpt,
-                opts.resetOffsetsOpt,
-                opts.deleteOpt,
-                opts.deleteOffsetsOpt
+                    opts.listOpt,
+                    opts.describeOpt,
+                    opts.resetOffsetsOpt,
+                    opts.deleteOpt,
+                    opts.deleteOffsetsOpt
             ).filter(opts.options::has).count();
             if (numberOfActions != 1)
-                CommandLineUtils.printUsageAndExit(opts.parser, "Command must 
include exactly one action: --list, --describe, --delete, --reset-offsets, or 
--delete-offsets.");
+                throw new IllegalArgumentException("Command must include 
exactly one action: --list, --describe, --delete, --reset-offsets, or 
--delete-offsets.");
 
             run(opts);
-        } catch (OptionException e) {
-            CommandLineUtils.printUsageAndExit(opts.parser, e.getMessage());
+        } catch (IllegalArgumentException | OptionException e) {
+            System.err.println(e.getMessage());
+            if (opts != null) {
+                try {
+                    opts.parser.printHelpOn(System.err);
+                } catch (IOException ex) {
+                    throw new RuntimeException(ex);
+                }
+            }
+            exitCode = 1;
+        } catch (Throwable e) {
+            printError("Executing streams group command failed due to " + 
e.getMessage(), Optional.of(e));
+            exitCode = 1;
         }
+
+        return exitCode;
     }
 
-    public static void run(StreamsGroupCommandOptions opts) {
+    public static void run(StreamsGroupCommandOptions opts) throws 
IllegalArgumentException, ExecutionException, InterruptedException {

Review Comment:
   Good catch. Agreed, I've already made the update.



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to