valepakh commented on code in PR #7382:
URL: https://github.com/apache/ignite-3/pull/7382#discussion_r2682266650
##########
modules/cli/src/main/java/org/apache/ignite/internal/cli/Main.java:
##########
@@ -53,25 +53,42 @@ public class Main {
public static void main(String[] args) {
initJavaLoggerProps();
+ // Determine if we're entering interactive REPL mode.
+ // REPL mode is only entered when no args AND stdin/stdout are
terminals.
+ boolean interactiveMode = args.length == 0 && isatty();
+
int exitCode = 0;
+ boolean ansiInstalled = false;
ApplicationContextBuilder builder =
ApplicationContext.builder(Environment.CLI).deduceEnvironment(false);
try (MicronautFactory micronautFactory = new
MicronautFactory(builder.start())) {
- AnsiConsole.systemInstall();
- initReplExecutor(micronautFactory);
- initQuestionAsker(micronautFactory);
- if (args.length != 0 || !isatty()) { // do not enter REPL if input
or output is redirected
+ if (interactiveMode) {
+ // REPL mode: full initialization with Jansi ANSI console and
JLine terminal.
+ AnsiConsole.systemInstall();
+ ansiInstalled = true;
+ initReplExecutor(micronautFactory);
+ initQuestionAsker(micronautFactory);
+ enterRepl(micronautFactory);
+ } else {
+ // Non-interactive mode: skip JLine terminal initialization
for faster startup.
+ // Only install ANSI console if stdout is a terminal (for
colored output).
+ if (isatty()) {
+ AnsiConsole.systemInstall();
+ ansiInstalled = true;
+ }
try {
exitCode = executeCommand(args, micronautFactory);
} catch (Exception e) {
- System.err.println("Error occurred during command
execution");
+ System.err.println("Error occurred during command
execution: " + e.getMessage());
+ exitCode = 1;
}
- } else {
- enterRepl(micronautFactory);
}
} catch (Exception e) {
- System.err.println("Error occurred during initialization");
+ System.err.println("Error occurred during initialization: " +
e.getMessage());
+ exitCode = 1;
} finally {
- AnsiConsole.systemUninstall();
+ if (ansiInstalled) {
Review Comment:
The boolean flag can be removed
```suggestion
if (AnsiConsole.isInstalled()) {
```
--
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]