This is an automated email from the ASF dual-hosted git repository.

apkhmv pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/ignite-3.git


The following commit(s) were added to refs/heads/main by this push:
     new 9cd1dad3af IGNITE-19078 Add connect question to `unit *` commands in 
REPL (#1829)
9cd1dad3af is described below

commit 9cd1dad3af51139181682058bd787cae55df4e3b
Author: Vadim Pakhnushev <[email protected]>
AuthorDate: Fri Mar 24 12:32:08 2023 +0300

    IGNITE-19078 Add connect question to `unit *` commands in REPL (#1829)
---
 .../cli/commands/TopLevelCliReplCommand.java       |  4 +-
 .../metric/NodeMetricSourceDisableCommand.java     |  2 +-
 .../node/metric/NodeMetricSourceEnableCommand.java |  2 +-
 .../node/metric/NodeMetricSourceListCommand.java   |  2 +-
 .../cli/commands/unit/UnitDeployCommand.java       | 13 +++++-
 ...ployCommand.java => UnitDeployReplCommand.java} | 48 +++++++++++++++-------
 .../cli/commands/unit/UnitListCommand.java         |  2 +-
 ...itListCommand.java => UnitListReplCommand.java} | 32 ++++++++-------
 .../cli/commands/unit/UnitReplCommand.java         | 32 +++++++++++++++
 .../cli/commands/unit/UnitStatusCommand.java       |  2 +-
 ...atusCommand.java => UnitStatusReplCommand.java} | 39 +++++++++---------
 .../cli/commands/unit/UnitUndeployCommand.java     |  2 +-
 ...oyCommand.java => UnitUndeployReplCommand.java} | 33 ++++++++-------
 .../cli/commands/UrlOptionsNegativeTest.java       | 16 ++++++++
 14 files changed, 155 insertions(+), 74 deletions(-)

diff --git 
a/modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/TopLevelCliReplCommand.java
 
b/modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/TopLevelCliReplCommand.java
index 8f4f289e1c..280abb9648 100644
--- 
a/modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/TopLevelCliReplCommand.java
+++ 
b/modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/TopLevelCliReplCommand.java
@@ -23,7 +23,7 @@ import 
org.apache.ignite.internal.cli.commands.connect.ConnectReplCommand;
 import org.apache.ignite.internal.cli.commands.connect.DisconnectCommand;
 import org.apache.ignite.internal.cli.commands.node.NodeReplCommand;
 import org.apache.ignite.internal.cli.commands.sql.SqlReplCommand;
-import org.apache.ignite.internal.cli.commands.unit.UnitCommand;
+import org.apache.ignite.internal.cli.commands.unit.UnitReplCommand;
 import org.apache.ignite.internal.cli.commands.version.VersionCommand;
 import picocli.CommandLine;
 import picocli.shell.jline3.PicocliCommands;
@@ -44,7 +44,7 @@ import picocli.shell.jline3.PicocliCommands;
                 DisconnectCommand.class,
                 NodeReplCommand.class,
                 ClusterReplCommand.class,
-                UnitCommand.class
+                UnitReplCommand.class
         })
 public class TopLevelCliReplCommand {
 }
diff --git 
a/modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/node/metric/NodeMetricSourceDisableCommand.java
 
b/modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/node/metric/NodeMetricSourceDisableCommand.java
index 562deb9c31..1529ec55de 100644
--- 
a/modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/node/metric/NodeMetricSourceDisableCommand.java
+++ 
b/modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/node/metric/NodeMetricSourceDisableCommand.java
@@ -49,7 +49,7 @@ public class NodeMetricSourceDisableCommand extends 
BaseCommand implements Calla
                 .output(spec.commandLine().getOut())
                 .errOutput(spec.commandLine().getErr())
                 .verbose(verbose)
-                .exceptionHandler(new 
ClusterNotInitializedExceptionHandler("Cannot disable metrics", "cluster init"))
+                .exceptionHandler(new 
ClusterNotInitializedExceptionHandler("Cannot disable metrics", "ignite cluster 
init"))
                 .build()
                 .runPipeline();
     }
diff --git 
a/modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/node/metric/NodeMetricSourceEnableCommand.java
 
b/modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/node/metric/NodeMetricSourceEnableCommand.java
index e82605220c..0c2fdd45d1 100644
--- 
a/modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/node/metric/NodeMetricSourceEnableCommand.java
+++ 
b/modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/node/metric/NodeMetricSourceEnableCommand.java
@@ -49,7 +49,7 @@ public class NodeMetricSourceEnableCommand extends 
BaseCommand implements Callab
                 .output(spec.commandLine().getOut())
                 .errOutput(spec.commandLine().getErr())
                 .verbose(verbose)
-                .exceptionHandler(new 
ClusterNotInitializedExceptionHandler("Cannot enable metrics", "cluster init"))
+                .exceptionHandler(new 
ClusterNotInitializedExceptionHandler("Cannot enable metrics", "ignite cluster 
init"))
                 .build()
                 .runPipeline();
     }
diff --git 
a/modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/node/metric/NodeMetricSourceListCommand.java
 
b/modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/node/metric/NodeMetricSourceListCommand.java
index 8447df2a42..ab1814ed2a 100644
--- 
a/modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/node/metric/NodeMetricSourceListCommand.java
+++ 
b/modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/node/metric/NodeMetricSourceListCommand.java
@@ -55,7 +55,7 @@ public class NodeMetricSourceListCommand extends BaseCommand 
implements Callable
                 .errOutput(spec.commandLine().getErr())
                 .decorator(new MetricSourceListDecorator(plain))
                 .verbose(verbose)
-                .exceptionHandler(new 
ClusterNotInitializedExceptionHandler("Cannot list metrics", "cluster init"))
+                .exceptionHandler(new 
ClusterNotInitializedExceptionHandler("Cannot list metrics", "ignite cluster 
init"))
                 .build()
                 .runPipeline();
     }
diff --git 
a/modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/unit/UnitDeployCommand.java
 
b/modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/unit/UnitDeployCommand.java
index 6745dbd44c..2ebf35d163 100644
--- 
a/modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/unit/UnitDeployCommand.java
+++ 
b/modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/unit/UnitDeployCommand.java
@@ -26,6 +26,7 @@ import static 
org.apache.ignite.internal.cli.commands.Options.Constants.UNIT_VER
 import static 
org.apache.ignite.internal.cli.commands.Options.Constants.VERSION_OPTION;
 
 import jakarta.inject.Inject;
+import java.nio.file.Files;
 import java.nio.file.Path;
 import java.util.concurrent.Callable;
 import org.apache.ignite.internal.cli.call.unit.DeployUnitCallFactory;
@@ -37,6 +38,7 @@ import 
org.apache.ignite.internal.cli.core.exception.handler.ClusterNotInitializ
 import picocli.CommandLine.Command;
 import picocli.CommandLine.Mixin;
 import picocli.CommandLine.Option;
+import picocli.CommandLine.ParameterException;
 import picocli.CommandLine.Parameters;
 
 /** Command to deploy a unit. */
@@ -55,9 +57,16 @@ public class UnitDeployCommand extends BaseCommand 
implements Callable<Integer>
     private String version;
 
     /** Unit path. */
-    @Option(names = {UNIT_PATH_OPTION, UNIT_PATH_OPTION_SHORT}, description = 
UNIT_PATH_OPTION_DESC, required = true)
     private Path path;
 
+    @Option(names = {UNIT_PATH_OPTION, UNIT_PATH_OPTION_SHORT}, description = 
UNIT_PATH_OPTION_DESC, required = true)
+    private void setPath(Path value) {
+        if (Files.notExists(value)) {
+            throw new ParameterException(spec.commandLine(), "No such file or 
directory: " + value);
+        }
+        path = value;
+    }
+
     @Inject
     private DeployUnitCallFactory callFactory;
 
@@ -73,7 +82,7 @@ public class UnitDeployCommand extends BaseCommand implements 
Callable<Integer>
                 .output(spec.commandLine().getOut())
                 .errOutput(spec.commandLine().getErr())
                 .verbose(verbose)
-                .exceptionHandler(new 
ClusterNotInitializedExceptionHandler("Cannot deploy unit", "cluster init"))
+                .exceptionHandler(new 
ClusterNotInitializedExceptionHandler("Cannot deploy unit", "ignite cluster 
init"))
                 .build().runPipeline();
     }
 }
diff --git 
a/modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/unit/UnitDeployCommand.java
 
b/modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/unit/UnitDeployReplCommand.java
similarity index 65%
copy from 
modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/unit/UnitDeployCommand.java
copy to 
modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/unit/UnitDeployReplCommand.java
index 6745dbd44c..3dfe89ec5a 100644
--- 
a/modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/unit/UnitDeployCommand.java
+++ 
b/modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/unit/UnitDeployReplCommand.java
@@ -26,25 +26,28 @@ import static 
org.apache.ignite.internal.cli.commands.Options.Constants.UNIT_VER
 import static 
org.apache.ignite.internal.cli.commands.Options.Constants.VERSION_OPTION;
 
 import jakarta.inject.Inject;
+import java.nio.file.Files;
 import java.nio.file.Path;
-import java.util.concurrent.Callable;
 import org.apache.ignite.internal.cli.call.unit.DeployUnitCallFactory;
 import org.apache.ignite.internal.cli.call.unit.DeployUnitCallInput;
 import org.apache.ignite.internal.cli.commands.BaseCommand;
-import org.apache.ignite.internal.cli.commands.cluster.ClusterUrlProfileMixin;
+import org.apache.ignite.internal.cli.commands.cluster.ClusterUrlMixin;
+import 
org.apache.ignite.internal.cli.commands.questions.ConnectToClusterQuestion;
 import org.apache.ignite.internal.cli.core.call.CallExecutionPipeline;
 import 
org.apache.ignite.internal.cli.core.exception.handler.ClusterNotInitializedExceptionHandler;
+import org.apache.ignite.internal.cli.core.flow.builder.Flows;
 import picocli.CommandLine.Command;
 import picocli.CommandLine.Mixin;
 import picocli.CommandLine.Option;
+import picocli.CommandLine.ParameterException;
 import picocli.CommandLine.Parameters;
 
-/** Command to deploy a unit. */
+/** Command to deploy a unit in REPL mode. */
 @Command(name = "deploy", description = "Deploys a unit")
-public class UnitDeployCommand extends BaseCommand implements 
Callable<Integer> {
+public class UnitDeployReplCommand extends BaseCommand implements Runnable {
 
     @Mixin
-    private ClusterUrlProfileMixin clusterUrl;
+    private ClusterUrlMixin clusterUrl;
 
     /** Unit id. */
     @Parameters(index = "0")
@@ -55,25 +58,40 @@ public class UnitDeployCommand extends BaseCommand 
implements Callable<Integer>
     private String version;
 
     /** Unit path. */
-    @Option(names = {UNIT_PATH_OPTION, UNIT_PATH_OPTION_SHORT}, description = 
UNIT_PATH_OPTION_DESC, required = true)
     private Path path;
 
+    @Option(names = {UNIT_PATH_OPTION, UNIT_PATH_OPTION_SHORT}, description = 
UNIT_PATH_OPTION_DESC, required = true)
+    private void setPath(Path value) {
+        if (Files.notExists(value)) {
+            throw new ParameterException(spec.commandLine(), "No such file or 
directory: " + value);
+        }
+        path = value;
+    }
+
     @Inject
     private DeployUnitCallFactory callFactory;
 
+    @Inject
+    private ConnectToClusterQuestion question;
+
     @Override
-    public Integer call() throws Exception {
-        return CallExecutionPipeline.asyncBuilder(callFactory::create)
-                .inputProvider(() -> DeployUnitCallInput.builder()
+    public void run() {
+        question.askQuestionIfNotConnected(clusterUrl.getClusterUrl())
+                .map(clusterUrl -> DeployUnitCallInput.builder()
                         .id(id)
                         .version(version)
                         .path(path)
-                        .clusterUrl(clusterUrl.getClusterUrl())
+                        .clusterUrl(clusterUrl)
                         .build())
-                .output(spec.commandLine().getOut())
-                .errOutput(spec.commandLine().getErr())
-                .verbose(verbose)
-                .exceptionHandler(new 
ClusterNotInitializedExceptionHandler("Cannot deploy unit", "cluster init"))
-                .build().runPipeline();
+                .then(Flows.mono(input ->
+                    CallExecutionPipeline.asyncBuilder(callFactory::create)
+                            .inputProvider(() -> input)
+                            .output(spec.commandLine().getOut())
+                            .errOutput(spec.commandLine().getErr())
+                            .verbose(verbose)
+                            .exceptionHandler(new 
ClusterNotInitializedExceptionHandler("Cannot deploy unit", "cluster init"))
+                            .build().runPipeline()
+                ))
+                .start();
     }
 }
diff --git 
a/modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/unit/UnitListCommand.java
 
b/modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/unit/UnitListCommand.java
index 8234cb6167..c7ff579fe9 100644
--- 
a/modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/unit/UnitListCommand.java
+++ 
b/modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/unit/UnitListCommand.java
@@ -48,7 +48,7 @@ public class UnitListCommand extends BaseCommand implements 
Callable<Integer> {
                 .errOutput(spec.commandLine().getErr())
                 .verbose(verbose)
                 .decorator(new UnitListDecorator())
-                .exceptionHandler(new 
ClusterNotInitializedExceptionHandler("Cannot list units", "cluster init"))
+                .exceptionHandler(new 
ClusterNotInitializedExceptionHandler("Cannot list units", "ignite cluster 
init"))
                 .build().runPipeline();
     }
 }
diff --git 
a/modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/unit/UnitListCommand.java
 
b/modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/unit/UnitListReplCommand.java
similarity index 69%
copy from 
modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/unit/UnitListCommand.java
copy to 
modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/unit/UnitListReplCommand.java
index 8234cb6167..ebd816446a 100644
--- 
a/modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/unit/UnitListCommand.java
+++ 
b/modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/unit/UnitListReplCommand.java
@@ -19,36 +19,38 @@ package org.apache.ignite.internal.cli.commands.unit;
 
 
 import jakarta.inject.Inject;
-import java.util.concurrent.Callable;
 import org.apache.ignite.internal.cli.call.unit.ListUnitCall;
 import org.apache.ignite.internal.cli.commands.BaseCommand;
-import org.apache.ignite.internal.cli.commands.cluster.ClusterUrlProfileMixin;
-import org.apache.ignite.internal.cli.core.call.CallExecutionPipeline;
+import org.apache.ignite.internal.cli.commands.cluster.ClusterUrlMixin;
+import 
org.apache.ignite.internal.cli.commands.questions.ConnectToClusterQuestion;
 import org.apache.ignite.internal.cli.core.call.UrlCallInput;
 import 
org.apache.ignite.internal.cli.core.exception.handler.ClusterNotInitializedExceptionHandler;
+import org.apache.ignite.internal.cli.core.flow.builder.Flows;
 import org.apache.ignite.internal.cli.decorators.UnitListDecorator;
 import picocli.CommandLine.Command;
 import picocli.CommandLine.Mixin;
 
-/** Command to list deployed units. */
+/** Command to list deployed units in REPL mode. */
 @Command(name = "list", description = "Shows a list of deployed units")
-public class UnitListCommand extends BaseCommand implements Callable<Integer> {
+public class UnitListReplCommand extends BaseCommand implements Runnable {
 
     @Mixin
-    private ClusterUrlProfileMixin clusterUrl;
+    private ClusterUrlMixin clusterUrl;
 
     @Inject
-    private ListUnitCall listUnitCall;
+    private ListUnitCall call;
+
+    @Inject
+    private ConnectToClusterQuestion question;
 
     @Override
-    public Integer call() throws Exception {
-        return CallExecutionPipeline.builder(listUnitCall)
-                .inputProvider(() -> new 
UrlCallInput(clusterUrl.getClusterUrl()))
-                .output(spec.commandLine().getOut())
-                .errOutput(spec.commandLine().getErr())
-                .verbose(verbose)
-                .decorator(new UnitListDecorator())
+    public void run() {
+        question.askQuestionIfNotConnected(clusterUrl.getClusterUrl())
+                .map(UrlCallInput::new)
+                .then(Flows.fromCall(call))
                 .exceptionHandler(new 
ClusterNotInitializedExceptionHandler("Cannot list units", "cluster init"))
-                .build().runPipeline();
+                .verbose(verbose)
+                .print(new UnitListDecorator())
+                .start();
     }
 }
diff --git 
a/modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/unit/UnitReplCommand.java
 
b/modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/unit/UnitReplCommand.java
new file mode 100644
index 0000000000..9aadecb0b2
--- /dev/null
+++ 
b/modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/unit/UnitReplCommand.java
@@ -0,0 +1,32 @@
+/*
+ * 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.ignite.internal.cli.commands.unit;
+
+import org.apache.ignite.internal.cli.commands.BaseCommand;
+import picocli.CommandLine.Command;
+
+/** Manages deployment units in REPL mode. */
+@Command(name = "unit", subcommands = {
+        UnitDeployReplCommand.class,
+        UnitUndeployReplCommand.class,
+        UnitListReplCommand.class,
+        UnitStatusReplCommand.class
+}, description = "Manages deployment units")
+public class UnitReplCommand extends BaseCommand {
+}
+
diff --git 
a/modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/unit/UnitStatusCommand.java
 
b/modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/unit/UnitStatusCommand.java
index 457df8f7f3..36bbc028a5 100644
--- 
a/modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/unit/UnitStatusCommand.java
+++ 
b/modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/unit/UnitStatusCommand.java
@@ -57,7 +57,7 @@ public class UnitStatusCommand extends BaseCommand implements 
Callable<Integer>
                 .errOutput(spec.commandLine().getErr())
                 .verbose(verbose)
                 .decorator(new UnitStatusDecorator())
-                .exceptionHandler(new 
ClusterNotInitializedExceptionHandler("Cannot get unit status", "cluster init"))
+                .exceptionHandler(new 
ClusterNotInitializedExceptionHandler("Cannot get unit status", "ignite cluster 
init"))
                 .build().runPipeline();
     }
 }
diff --git 
a/modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/unit/UnitStatusCommand.java
 
b/modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/unit/UnitStatusReplCommand.java
similarity index 66%
copy from 
modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/unit/UnitStatusCommand.java
copy to 
modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/unit/UnitStatusReplCommand.java
index 457df8f7f3..bd612115de 100644
--- 
a/modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/unit/UnitStatusCommand.java
+++ 
b/modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/unit/UnitStatusReplCommand.java
@@ -19,45 +19,46 @@ package org.apache.ignite.internal.cli.commands.unit;
 
 
 import jakarta.inject.Inject;
-import java.util.concurrent.Callable;
 import org.apache.ignite.internal.cli.call.unit.UnitStatusCall;
 import org.apache.ignite.internal.cli.call.unit.UnitStatusCallInput;
 import org.apache.ignite.internal.cli.commands.BaseCommand;
-import org.apache.ignite.internal.cli.commands.cluster.ClusterUrlProfileMixin;
-import org.apache.ignite.internal.cli.core.call.CallExecutionPipeline;
+import org.apache.ignite.internal.cli.commands.cluster.ClusterUrlMixin;
+import 
org.apache.ignite.internal.cli.commands.questions.ConnectToClusterQuestion;
 import 
org.apache.ignite.internal.cli.core.exception.handler.ClusterNotInitializedExceptionHandler;
+import org.apache.ignite.internal.cli.core.flow.builder.Flows;
 import org.apache.ignite.internal.cli.decorators.UnitStatusDecorator;
 import picocli.CommandLine.Command;
 import picocli.CommandLine.Mixin;
 import picocli.CommandLine.Parameters;
 
-/** Command to show status of the unit. */
+/** Command to show status of the unit in REPL mode. */
 @Command(name = "status", description = "Shows status of the unit")
-public class UnitStatusCommand extends BaseCommand implements 
Callable<Integer> {
+public class UnitStatusReplCommand extends BaseCommand implements Runnable {
 
     @Mixin
-    private ClusterUrlProfileMixin clusterUrl;
+    private ClusterUrlMixin clusterUrl;
 
     /** Unit id. */
     @Parameters(index = "0")
     private String id;
 
     @Inject
-    private UnitStatusCall statusCall;
+    private UnitStatusCall call;
+
+    @Inject
+    private ConnectToClusterQuestion question;
 
     @Override
-    public Integer call() throws Exception {
-        return CallExecutionPipeline.builder(statusCall)
-                .inputProvider(() ->
-                        UnitStatusCallInput.builder()
-                                .id(id)
-                                .clusterUrl(clusterUrl.getClusterUrl())
-                                .build())
-                .output(spec.commandLine().getOut())
-                .errOutput(spec.commandLine().getErr())
-                .verbose(verbose)
-                .decorator(new UnitStatusDecorator())
+    public void run() {
+        question.askQuestionIfNotConnected(clusterUrl.getClusterUrl())
+                .map(clusterUrl -> UnitStatusCallInput.builder()
+                        .id(id)
+                        .clusterUrl(clusterUrl)
+                        .build())
+                .then(Flows.fromCall(call))
                 .exceptionHandler(new 
ClusterNotInitializedExceptionHandler("Cannot get unit status", "cluster init"))
-                .build().runPipeline();
+                .verbose(verbose)
+                .print(new UnitStatusDecorator())
+                .start();
     }
 }
diff --git 
a/modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/unit/UnitUndeployCommand.java
 
b/modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/unit/UnitUndeployCommand.java
index 6cfd3e734d..6c47a9fd92 100644
--- 
a/modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/unit/UnitUndeployCommand.java
+++ 
b/modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/unit/UnitUndeployCommand.java
@@ -64,7 +64,7 @@ public class UnitUndeployCommand extends BaseCommand 
implements Callable<Integer
                 .output(spec.commandLine().getOut())
                 .errOutput(spec.commandLine().getErr())
                 .verbose(verbose)
-                .exceptionHandler(new 
ClusterNotInitializedExceptionHandler("Cannot undeploy unit", "cluster init"))
+                .exceptionHandler(new 
ClusterNotInitializedExceptionHandler("Cannot undeploy unit", "ignite cluster 
init"))
                 .build().runPipeline();
     }
 }
diff --git 
a/modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/unit/UnitUndeployCommand.java
 
b/modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/unit/UnitUndeployReplCommand.java
similarity index 76%
copy from 
modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/unit/UnitUndeployCommand.java
copy to 
modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/unit/UnitUndeployReplCommand.java
index 6cfd3e734d..96dd20295d 100644
--- 
a/modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/unit/UnitUndeployCommand.java
+++ 
b/modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/unit/UnitUndeployReplCommand.java
@@ -23,24 +23,24 @@ import static 
org.apache.ignite.internal.cli.commands.Options.Constants.UNIT_VER
 import static 
org.apache.ignite.internal.cli.commands.Options.Constants.VERSION_OPTION;
 
 import jakarta.inject.Inject;
-import java.util.concurrent.Callable;
 import org.apache.ignite.internal.cli.call.unit.UndeployUnitCall;
 import org.apache.ignite.internal.cli.call.unit.UndeployUnitCallInput;
 import org.apache.ignite.internal.cli.commands.BaseCommand;
-import org.apache.ignite.internal.cli.commands.cluster.ClusterUrlProfileMixin;
-import org.apache.ignite.internal.cli.core.call.CallExecutionPipeline;
+import org.apache.ignite.internal.cli.commands.cluster.ClusterUrlMixin;
+import 
org.apache.ignite.internal.cli.commands.questions.ConnectToClusterQuestion;
 import 
org.apache.ignite.internal.cli.core.exception.handler.ClusterNotInitializedExceptionHandler;
+import org.apache.ignite.internal.cli.core.flow.builder.Flows;
 import picocli.CommandLine.Command;
 import picocli.CommandLine.Mixin;
 import picocli.CommandLine.Option;
 import picocli.CommandLine.Parameters;
 
-/** Command to undeploy a unit. */
+/** Command to undeploy a unit in REPL mode. */
 @Command(name = "undeploy", description = "Undeploys a unit")
-public class UnitUndeployCommand extends BaseCommand implements 
Callable<Integer> {
+public class UnitUndeployReplCommand extends BaseCommand implements Runnable {
 
     @Mixin
-    private ClusterUrlProfileMixin clusterUrl;
+    private ClusterUrlMixin clusterUrl;
 
     /** Unit id. */
     @Parameters(index = "0", description = "Unit id")
@@ -51,20 +51,23 @@ public class UnitUndeployCommand extends BaseCommand 
implements Callable<Integer
     private String version;
 
     @Inject
-    private UndeployUnitCall undeployUnitCall;
+    private UndeployUnitCall call;
+
+    @Inject
+    private ConnectToClusterQuestion question;
 
     @Override
-    public Integer call() throws Exception {
-        return CallExecutionPipeline.builder(undeployUnitCall)
-                .inputProvider(() -> UndeployUnitCallInput.builder()
+    public void run() {
+        question.askQuestionIfNotConnected(clusterUrl.getClusterUrl())
+                .map(clusterUrl -> UndeployUnitCallInput.builder()
                         .id(id)
                         .version(version)
-                        .clusterUrl(clusterUrl.getClusterUrl())
+                        .clusterUrl(clusterUrl)
                         .build())
-                .output(spec.commandLine().getOut())
-                .errOutput(spec.commandLine().getErr())
-                .verbose(verbose)
+                .then(Flows.fromCall(call))
                 .exceptionHandler(new 
ClusterNotInitializedExceptionHandler("Cannot undeploy unit", "cluster init"))
-                .build().runPipeline();
+                .verbose(verbose)
+                .print()
+                .start();
     }
 }
diff --git 
a/modules/cli/src/test/java/org/apache/ignite/internal/cli/commands/UrlOptionsNegativeTest.java
 
b/modules/cli/src/test/java/org/apache/ignite/internal/cli/commands/UrlOptionsNegativeTest.java
index 6c9bd3b2ad..47d0081d59 100644
--- 
a/modules/cli/src/test/java/org/apache/ignite/internal/cli/commands/UrlOptionsNegativeTest.java
+++ 
b/modules/cli/src/test/java/org/apache/ignite/internal/cli/commands/UrlOptionsNegativeTest.java
@@ -59,6 +59,12 @@ import 
org.apache.ignite.internal.cli.commands.node.metric.NodeMetricSourceListC
 import 
org.apache.ignite.internal.cli.commands.node.metric.NodeMetricSourceListReplCommand;
 import org.apache.ignite.internal.cli.commands.node.status.NodeStatusCommand;
 import 
org.apache.ignite.internal.cli.commands.node.status.NodeStatusReplCommand;
+import org.apache.ignite.internal.cli.commands.unit.UnitListCommand;
+import org.apache.ignite.internal.cli.commands.unit.UnitListReplCommand;
+import org.apache.ignite.internal.cli.commands.unit.UnitStatusCommand;
+import org.apache.ignite.internal.cli.commands.unit.UnitStatusReplCommand;
+import org.apache.ignite.internal.cli.commands.unit.UnitUndeployCommand;
+import org.apache.ignite.internal.cli.commands.unit.UnitUndeployReplCommand;
 import org.apache.ignite.internal.cli.config.ini.IniConfigManager;
 import org.apache.ignite.internal.cli.core.converters.NodeNameOrUrlConverter;
 import 
org.apache.ignite.internal.cli.core.repl.context.CommandLineContextProvider;
@@ -131,6 +137,11 @@ public class UrlOptionsNegativeTest {
                 arguments(NodeMetricSetListCommand.class, NODE_URL_OPTION, 
List.of()),
                 arguments(LogicalTopologyCommand.class, CLUSTER_URL_OPTION, 
List.of()),
                 arguments(PhysicalTopologyCommand.class, CLUSTER_URL_OPTION, 
List.of()),
+                // TODO https://issues.apache.org/jira/browse/IGNITE-19090
+                // arguments(UnitDeployCommand.class, CLUSTER_URL_OPTION, 
List.of("--path=" + TEMP_FILE_PATH, "id")),
+                arguments(UnitUndeployCommand.class, CLUSTER_URL_OPTION, 
List.of("id")),
+                arguments(UnitStatusCommand.class, CLUSTER_URL_OPTION, 
List.of("id")),
+                arguments(UnitListCommand.class, CLUSTER_URL_OPTION, 
List.of()),
                 arguments(ClusterInitCommand.class, CLUSTER_URL_OPTION, 
List.of("--cluster-name=cluster", "--meta-storage-node=test"))
         // TODO https://issues.apache.org/jira/browse/IGNITE-17102
         //                Arguments.arguments(ClusterShowCommand.class, 
CLUSTER_URL_OPTION, List.of()),
@@ -151,6 +162,11 @@ public class UrlOptionsNegativeTest {
                 arguments(NodeMetricSetListReplCommand.class, NODE_URL_OPTION, 
List.of()),
                 arguments(LogicalTopologyReplCommand.class, 
CLUSTER_URL_OPTION, List.of()),
                 arguments(PhysicalTopologyReplCommand.class, 
CLUSTER_URL_OPTION, List.of()),
+                // TODO https://issues.apache.org/jira/browse/IGNITE-19090
+                // arguments(UnitDeployReplCommand.class, CLUSTER_URL_OPTION, 
List.of("--path=" + TEMP_FILE_PATH, "id")),
+                arguments(UnitUndeployReplCommand.class, CLUSTER_URL_OPTION, 
List.of("id")),
+                arguments(UnitStatusReplCommand.class, CLUSTER_URL_OPTION, 
List.of("id")),
+                arguments(UnitListReplCommand.class, CLUSTER_URL_OPTION, 
List.of()),
                 arguments(ClusterInitReplCommand.class, CLUSTER_URL_OPTION, 
List.of("--cluster-name=cluster", "--meta-storage-node=test")),
                 arguments(ConnectReplCommand.class, "", List.of())
         // TODO https://issues.apache.org/jira/browse/IGNITE-17102

Reply via email to