smiklosovic commented on code in PR #4617:
URL: https://github.com/apache/cassandra/pull/4617#discussion_r2839491865
##########
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:
maybe you could do something like this to reuse:
public class PrintPortMixin
{
private static final String PRINT_PORT_SHORT = "-pp";
private static final String PRINT_PORT_LONG = "--print-port";
public static final Set<String> OPTIONS = Set.of(PRINT_PORT_SHORT,
PRINT_PORT_LONG);
@CommandLine.Option(names = { PRINT_PORT_SHORT, PRINT_PORT_LONG } ...
}
and then here `PrintPortMixin.OPTIONS`.
--
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]