netudima commented on code in PR #2497:
URL: https://github.com/apache/cassandra/pull/2497#discussion_r2094153930


##########
src/java/org/apache/cassandra/tools/NodeTool.java:
##########
@@ -356,208 +217,52 @@ protected void err(Throwable e)
         output.err.println(getStackTraceAsString(e));
     }
 
-    public static class CassHelp extends Help implements NodeToolCmdRunnable
-    {
-        public void run(INodeProbeFactory nodeProbeFactory, Output output)
-        {
-            run();
-        }
-    }
-
-    interface NodeToolCmdRunnable
+    private enum CliLayout
     {
-        void run(INodeProbeFactory nodeProbeFactory, Output output);
+        AIRLINE,
+        PICOCLI
     }
 
-    public static abstract class NodeToolCmd implements NodeToolCmdRunnable
+    private static class CassandraCliFactory implements CommandLine.IFactory
     {
+        private final CommandLine.IFactory fallback;
+        private final INodeProbeFactory nodeProbeFactory;
+        private final Output output;
 
-        @Option(type = OptionType.GLOBAL, name = {"-h", "--host"}, description 
= "Node hostname or ip address")
-        private String host = "127.0.0.1";
-
-        @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:
   do we ignore @Inject fields which we cannot set intentionally?



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