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


##########
src/java/org/apache/cassandra/tools/NodeTool.java:
##########
@@ -333,206 +211,52 @@ protected void err(Throwable e)
         output.err.println(getStackTraceAsString(e));
     }
 
-    public static class CassHelp extends Help implements NodeToolCmdRunnable
+    private enum CliLayout
     {
-        public void run(INodeProbeFactory nodeProbeFactory, Output output)
-        {
-            run();
-        }
+        AIRLINE,
+        PICOCLI
     }
 
-    interface NodeToolCmdRunnable
+    private static class CassandraCliFactory implements CommandLine.IFactory
     {
-        void run(INodeProbeFactory nodeProbeFactory, Output output);
-    }
-
-    public static abstract class NodeToolCmd implements NodeToolCmdRunnable
-    {
-
-        @Option(type = OptionType.GLOBAL, name = {"-h", "--host"}, description 
= "Node hostname or ip address")
-        private String host = "127.0.0.1";
+        private final CommandLine.IFactory fallback;
+        private final INodeProbeFactory nodeProbeFactory;
+        private final Output output;
 
-        @Option(type = OptionType.GLOBAL, name = {"-p", "--port"}, description 
= "Remote jmx agent port number")
-        private String port = "7199";
-
-        @Option(type = OptionType.GLOBAL, name = {"-u", "--username"}, 
description = "Remote jmx agent username")
-        private String username = EMPTY;
-
-        @Option(type = OptionType.GLOBAL, name = {"-pw", "--password"}, 
description = "Remote jmx agent password")
-        private String password = EMPTY;
-
-        @Option(type = OptionType.GLOBAL, name = {"-pwf", "--password-file"}, 
description = "Path to the JMX password file")
-        private String passwordFilePath = EMPTY;
-
-        @Option(type = OptionType.GLOBAL, name = { "-pp", "--print-port"}, 
description = "Operate in 4.0 mode with hosts disambiguated by port number", 
arity = 0)
-        protected boolean printPort = false;
-
-        private INodeProbeFactory nodeProbeFactory;
-        protected Output output;
-
-        @Override
-        public void run(INodeProbeFactory nodeProbeFactory, Output output)
+        public CassandraCliFactory(INodeProbeFactory nodeProbeFactory, Output 
output)
         {
+            this.fallback = CommandLine.defaultFactory();
             this.nodeProbeFactory = nodeProbeFactory;
             this.output = output;
-            runInternal();
         }
 
-        public void runInternal()
+        public <K> K create(Class<K> cls)
         {
-            if (isNotEmpty(username)) {
-                if (isNotEmpty(passwordFilePath))
-                    password = readUserPasswordFromFile(username, 
passwordFilePath);
-
-                if (isEmpty(password))
-                    password = promptAndReadPassword();
-            }
-
-            try (NodeProbe probe = connect())
-            {
-                execute(probe);
-                if (probe.isFailed())
-                    throw new RuntimeException("nodetool failed, check server 
logs");
-            }
-            catch (IOException e)
-            {
-                throw new RuntimeException("Error while closing JMX 
connection", e);
-            }
-
-        }
-
-        private String readUserPasswordFromFile(String username, String 
passwordFilePath) {
-            String password = EMPTY;
-
-            File passwordFile = new File(passwordFilePath);
-            try (Scanner scanner = new 
Scanner(passwordFile.toJavaIOFile()).useDelimiter("\\s+"))
+            try
             {
-                while (scanner.hasNextLine())
+                K bean = this.fallback.create(cls);
+                Class<?> beanClass = bean.getClass();
+                do
                 {
-                    if (scanner.hasNext())
+                    Field[] fields = beanClass.getDeclaredFields();
+                    for (Field field : fields)
                     {
-                        String jmxRole = scanner.next();
-                        if (jmxRole.equals(username) && scanner.hasNext())
-                        {
-                            password = scanner.next();
-                            break;
-                        }
+                        if (!field.isAnnotationPresent(Inject.class))
+                            continue;
+                        field.setAccessible(true);

Review Comment:
   I've added a new test to verify this: `NodetoolClassHierarchyTest`. It also 
helps to verify that we are not missing injectable fields to inject.



-- 
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: pr-unsubscr...@cassandra.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: pr-unsubscr...@cassandra.apache.org
For additional commands, e-mail: pr-h...@cassandra.apache.org

Reply via email to