[ 
https://issues.apache.org/jira/browse/ARTEMIS-4372?focusedWorklogId=873790&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-873790
 ]

ASF GitHub Bot logged work on ARTEMIS-4372:
-------------------------------------------

                Author: ASF GitHub Bot
            Created on: 31/Jul/23 12:39
            Start Date: 31/Jul/23 12:39
    Worklog Time Spent: 10m 
      Work Description: gnodet commented on code in PR #4565:
URL: https://github.com/apache/activemq-artemis/pull/4565#discussion_r1279185868


##########
artemis-cli/src/main/java/org/apache/activemq/artemis/cli/Shell.java:
##########
@@ -0,0 +1,128 @@
+/*
+ * 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.activemq.artemis.cli;
+
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.function.Supplier;
+
+import org.jline.console.SystemRegistry;
+import org.jline.console.impl.SystemRegistryImpl;
+import org.jline.reader.EndOfFileException;
+import org.jline.reader.LineReader;
+import org.jline.reader.LineReaderBuilder;
+import org.jline.reader.MaskingCallback;
+import org.jline.reader.Parser;
+import org.jline.reader.UserInterruptException;
+import org.jline.reader.impl.DefaultParser;
+import org.jline.terminal.Terminal;
+import org.jline.terminal.TerminalBuilder;
+import picocli.CommandLine;
+import picocli.CommandLine.Command;
+import picocli.shell.jline3.PicocliCommands;
+
+@Command(name = "shell", description = "JLine3 shell helping using the CLI")
+public class Shell implements Runnable {
+
+   private static String RED_UNICODE = "\u001B[31m";
+   private static String YELLOW_UNICODE = "\u001B[33m";
+   private static String CLEAR_UNICODE = "\u001B[0m";
+
+   public Shell(CommandLine commandLine) {
+   }
+
+   @Override
+   public void run() {
+      runShell();
+   }
+
+   private static ThreadLocal<AtomicBoolean> IN_SHELL = 
ThreadLocal.withInitial(() -> new AtomicBoolean(false));
+
+   public static boolean inShell() {
+      return IN_SHELL.get().get();
+   }
+
+   public static void runShell() {
+      try {
+         IN_SHELL.get().set(true);
+
+         boolean isInstance = System.getProperty("artemis.instance") != null;
+
+         Supplier<Path> workDir = () -> 
Paths.get(System.getProperty("user.dir"));
+
+         PicocliCommands.PicocliCommandsFactory factory = new 
PicocliCommands.PicocliCommandsFactory();
+
+         CommandLine commandLine = Artemis.buildCommand(isInstance, 
!isInstance, true);
+
+         PicocliCommands picocliCommands = new PicocliCommands(commandLine);
+
+         Parser parser = new DefaultParser();
+         try (Terminal terminal = TerminalBuilder.builder().build()) {

Review Comment:
   As a shortcut, you could use `TerminalBuilder.terminal()`



##########
artemis-distribution/src/main/resources/bin/artemis:
##########
@@ -91,6 +91,9 @@ if $cygwin ; then
 fi
 
 exec "$JAVACMD" $JAVA_ARGS $ARTEMIS_CLUSTER_PROPS \
+    --add-opens java.base/java.lang=ALL-UNNAMED \
+    --add-opens java.base/java.io=ALL-UNNAMED \
+    --add-opens java.base/java.util=ALL-UNNAMED \

Review Comment:
   See above, adding jansi will remove the need for those options.



##########
artemis-cli/src/main/resources/org/apache/activemq/artemis/cli/commands/bin/artemis:
##########
@@ -102,6 +102,9 @@ fi
 
 exec "$JAVACMD" \
     $JAVA_ARGS \
+    --add-opens java.base/java.lang=ALL-UNNAMED \
+    --add-opens java.base/java.io=ALL-UNNAMED \
+    --add-opens java.base/java.util=ALL-UNNAMED \

Review Comment:
   Adding the jansi library will remove the need for those additional JVM 
options.  Those are only required when using the exec provider, which won't be 
used if you add jansi to support windows.



##########
artemis-cli/pom.xml:
##########
@@ -124,10 +124,17 @@
          <artifactId>jakarta.xml.bind-api</artifactId>
          <version>${jakarta.xml.bind-api.version}</version>
       </dependency>
-
       <dependency>
-         <groupId>com.github.rvesse</groupId>
-         <artifactId>airline</artifactId>
+         <groupId>info.picocli</groupId>
+         <artifactId>picocli</artifactId>
+      </dependency>
+      <dependency>
+         <groupId>info.picocli</groupId>
+         <artifactId>picocli-shell-jline3</artifactId>
+      </dependency>
+      <dependency>
+         <groupId>org.jline</groupId>
+         <artifactId>jline</artifactId>

Review Comment:
   In order to support Windows properly, you need to add a dependency on jansi 
or jna.  I suggest jansi which is more lightweight.
   ```
               <dependency>
                   <groupId>org.fusesource.jansi</groupId>
                   <artifactId>jansi</artifactId>
                   <version>2.4.0</version>
               </dependency>
   ```
   





Issue Time Tracking
-------------------

    Worklog Id:     (was: 873790)
    Time Spent: 5h 20m  (was: 5h 10m)

> Move CLI framework to picocli and implement auto-complete
> ---------------------------------------------------------
>
>                 Key: ARTEMIS-4372
>                 URL: https://issues.apache.org/jira/browse/ARTEMIS-4372
>             Project: ActiveMQ Artemis
>          Issue Type: New Feature
>            Reporter: Clebert Suconic
>            Assignee: Clebert Suconic
>            Priority: Major
>             Fix For: 2.31.0
>
>          Time Spent: 5h 20m
>  Remaining Estimate: 0h
>




--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to