Mmuzaf commented on code in PR #4617:
URL: https://github.com/apache/cassandra/pull/4617#discussion_r2867830902


##########
test/unit/org/apache/cassandra/tools/nodetool/NodetoolPrintPortBackwardCompatibilityTest.java:
##########
@@ -0,0 +1,123 @@
+/*
+ * 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.cassandra.tools.nodetool;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+
+import org.apache.cassandra.cql3.CQLTester;
+import org.apache.cassandra.tools.ToolRunner;
+
+/**
+ * Verifies backward compatibility of the {@code -pp/--print-port} option 
placement.
+ * For each command in {@code PRINT_PORT_COMMANDS}, both syntaxes must succeed:
+ * <ul>
+ *   <li>{@code nodetool <command> --print-port} (natural picocli parsing via 
{@link PrintPortMixin})</li>
+ *   <li>{@code nodetool --print-port <command>} (backward-compatible 
relocation)</li>
+ * </ul>
+ * Commands that do not accept {@code --print-port} must reject it.
+ */
+@RunWith(Parameterized.class)
+public class NodetoolPrintPortBackwardCompatibilityTest extends CQLTester
+{
+    private static final String[] DEAFULT_STRING_ARRAY = new String[0];
+
+    @Parameterized.Parameter
+    public String command;
+
+    @Parameterized.Parameter(1)
+    public String[] extraArgs;
+
+    @Parameterized.Parameters(name = "{0}")
+    public static Collection<Object[]> data()
+    {
+        return List.of(
+            new Object[]{ "status", DEAFULT_STRING_ARRAY },

Review Comment:
   Fixed.



##########
src/java/org/apache/cassandra/tools/NodeTool.java:
##########
@@ -220,6 +235,66 @@ protected void err(Throwable e)
         output.err.println(getStackTraceAsString(e));
     }
 
+    /**
+     * Rewrites global {@code -pp/--print-port} options that have been moved
+     * to subcommands via @Mixin for backward compatibility. When a user types:
+     * <pre>
+     *   nodetool -pp status
+     *   nodetool --print-port status -r
+     * </pre>
+     * this method rewrites them to:
+     * <pre>
+     *   nodetool status -pp
+     *   nodetool status -r --print-port
+     * </pre>
+     * so that picocli assigns the option to the subcommand that declares it.
+     * <p>
+     * Options that appear after the subcommand name are left untouched:
+     * <pre>
+     *   nodetool status -pp        -> unchanged
+     *   nodetool status -pp -r     -> unchanged
+     * </pre>
+     */
+    static String[] relocatePrintPortOptionsForBackwardCompatibility(String[] 
args)
+    {
+        if (args == null || args.length < 2)
+            return args;
+
+        Set<String> relocatable = Set.of("-pp", "--print-port");

Review Comment:
   Fixed.



-- 
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]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to