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 065700d196 IGNITE-22675 Recovery CLI commands don't accept profile 
option (#4053)
065700d196 is described below

commit 065700d1969b3c39f6b8c5799469f9376c4ef186
Author: Vadim Pakhnushev <[email protected]>
AuthorDate: Mon Jul 8 16:38:34 2024 +0300

    IGNITE-22675 Recovery CLI commands don't accept profile option (#4053)
---
 .../recovery/reset/ResetPartitionsCallInput.java   |  4 -
 .../restart/RestartPartitionsCallInput.java        |  4 -
 .../recovery/{ => states}/PartitionStatesCall.java |  2 +-
 .../{ => states}/PartitionStatesCallInput.java     |  6 +-
 .../partitions/reset/ResetPartitionsCommand.java   |  7 +-
 .../partitions/reset/ResetPartitionsMixin.java     | 10 ---
 .../reset/ResetPartitionsReplCommand.java          |  7 +-
 .../restart/RestartPartitionsCommand.java          |  7 +-
 .../partitions/restart/RestartPartitionsMixin.java | 10 ---
 .../restart/RestartPartitionsReplCommand.java      |  7 +-
 .../partitions/states/PartitionStatesCommand.java  | 11 ++-
 .../partitions/states/PartitionStatesMixin.java    | 10 ---
 .../states/PartitionStatesReplCommand.java         | 11 ++-
 .../internal/cli/commands/ProfileMixinTest.java    | 61 ++++++++++++++
 .../internal/cli/commands/ProfileOptionTest.java   | 97 ++++++++++++++++++++++
 15 files changed, 200 insertions(+), 54 deletions(-)

diff --git 
a/modules/cli/src/main/java/org/apache/ignite/internal/cli/call/recovery/reset/ResetPartitionsCallInput.java
 
b/modules/cli/src/main/java/org/apache/ignite/internal/cli/call/recovery/reset/ResetPartitionsCallInput.java
index 5cd75cd348..4f879215fd 100644
--- 
a/modules/cli/src/main/java/org/apache/ignite/internal/cli/call/recovery/reset/ResetPartitionsCallInput.java
+++ 
b/modules/cli/src/main/java/org/apache/ignite/internal/cli/call/recovery/reset/ResetPartitionsCallInput.java
@@ -64,10 +64,6 @@ public class ResetPartitionsCallInput implements CallInput {
         this.partitionIds = partitionIds == null ? List.of() : 
List.copyOf(partitionIds);
     }
 
-    public static ResetPartitionsCallInput of(ResetPartitionsMixin statesArgs) 
{
-        return of(statesArgs, statesArgs.clusterUrl());
-    }
-
     /** Returns {@link ResetPartitionsCallInput} with specified arguments. */
     public static ResetPartitionsCallInput of(ResetPartitionsMixin statesArgs, 
String clusterUrl) {
         return builder()
diff --git 
a/modules/cli/src/main/java/org/apache/ignite/internal/cli/call/recovery/restart/RestartPartitionsCallInput.java
 
b/modules/cli/src/main/java/org/apache/ignite/internal/cli/call/recovery/restart/RestartPartitionsCallInput.java
index fb8ac35bbf..e541bef10c 100644
--- 
a/modules/cli/src/main/java/org/apache/ignite/internal/cli/call/recovery/restart/RestartPartitionsCallInput.java
+++ 
b/modules/cli/src/main/java/org/apache/ignite/internal/cli/call/recovery/restart/RestartPartitionsCallInput.java
@@ -73,10 +73,6 @@ public class RestartPartitionsCallInput implements CallInput 
{
         this.nodeNames = nodeNames == null ? List.of() : 
List.copyOf(nodeNames);
     }
 
-    public static RestartPartitionsCallInput of(RestartPartitionsMixin 
statesArgs) {
-        return of(statesArgs, statesArgs.clusterUrl());
-    }
-
     /** Returns {@link RestartPartitionsCallInput} with specified arguments. */
     public static RestartPartitionsCallInput of(RestartPartitionsMixin 
restartArgs, String clusterUrl) {
         return builder()
diff --git 
a/modules/cli/src/main/java/org/apache/ignite/internal/cli/call/recovery/PartitionStatesCall.java
 
b/modules/cli/src/main/java/org/apache/ignite/internal/cli/call/recovery/states/PartitionStatesCall.java
similarity index 98%
rename from 
modules/cli/src/main/java/org/apache/ignite/internal/cli/call/recovery/PartitionStatesCall.java
rename to 
modules/cli/src/main/java/org/apache/ignite/internal/cli/call/recovery/states/PartitionStatesCall.java
index de75d79069..6a6acb869d 100644
--- 
a/modules/cli/src/main/java/org/apache/ignite/internal/cli/call/recovery/PartitionStatesCall.java
+++ 
b/modules/cli/src/main/java/org/apache/ignite/internal/cli/call/recovery/states/PartitionStatesCall.java
@@ -15,7 +15,7 @@
  * limitations under the License.
  */
 
-package org.apache.ignite.internal.cli.call.recovery;
+package org.apache.ignite.internal.cli.call.recovery.states;
 
 import static java.util.stream.Collectors.toList;
 
diff --git 
a/modules/cli/src/main/java/org/apache/ignite/internal/cli/call/recovery/PartitionStatesCallInput.java
 
b/modules/cli/src/main/java/org/apache/ignite/internal/cli/call/recovery/states/PartitionStatesCallInput.java
similarity index 96%
rename from 
modules/cli/src/main/java/org/apache/ignite/internal/cli/call/recovery/PartitionStatesCallInput.java
rename to 
modules/cli/src/main/java/org/apache/ignite/internal/cli/call/recovery/states/PartitionStatesCallInput.java
index a2ae4fc837..26ac3e6aef 100644
--- 
a/modules/cli/src/main/java/org/apache/ignite/internal/cli/call/recovery/PartitionStatesCallInput.java
+++ 
b/modules/cli/src/main/java/org/apache/ignite/internal/cli/call/recovery/states/PartitionStatesCallInput.java
@@ -15,7 +15,7 @@
  * limitations under the License.
  */
 
-package org.apache.ignite.internal.cli.call.recovery;
+package org.apache.ignite.internal.cli.call.recovery.states;
 
 import java.util.List;
 import 
org.apache.ignite.internal.cli.commands.recovery.partitions.states.PartitionStatesMixin;
@@ -73,10 +73,6 @@ public class PartitionStatesCallInput implements CallInput {
         this.partitionIds = partitionIds == null ? List.of() : 
List.copyOf(partitionIds);
     }
 
-    public static PartitionStatesCallInput of(PartitionStatesMixin statesArgs) 
{
-        return of(statesArgs, statesArgs.clusterUrl());
-    }
-
     /** Returns {@link PartitionStatesCallInput} with specified arguments. */
     public static PartitionStatesCallInput of(PartitionStatesMixin statesArgs, 
String clusterUrl) {
         return builder()
diff --git 
a/modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/recovery/partitions/reset/ResetPartitionsCommand.java
 
b/modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/recovery/partitions/reset/ResetPartitionsCommand.java
index 33330ed018..088c75b43d 100644
--- 
a/modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/recovery/partitions/reset/ResetPartitionsCommand.java
+++ 
b/modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/recovery/partitions/reset/ResetPartitionsCommand.java
@@ -22,6 +22,7 @@ import java.util.concurrent.Callable;
 import org.apache.ignite.internal.cli.call.recovery.reset.ResetPartitionsCall;
 import 
org.apache.ignite.internal.cli.call.recovery.reset.ResetPartitionsCallInput;
 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.core.exception.handler.ClusterNotInitializedExceptionHandler;
 import picocli.CommandLine.Command;
@@ -30,6 +31,10 @@ import picocli.CommandLine.Mixin;
 /** Command to reset partitions. */
 @Command(name = "reset", description = "Resets partitions.")
 public class ResetPartitionsCommand extends BaseCommand implements 
Callable<Integer> {
+    /** Cluster endpoint URL option. */
+    @Mixin
+    private ClusterUrlProfileMixin clusterUrl;
+
     @Mixin
     private ResetPartitionsMixin options;
 
@@ -39,7 +44,7 @@ public class ResetPartitionsCommand extends BaseCommand 
implements Callable<Inte
     @Override
     public Integer call() {
         return CallExecutionPipeline.builder(call)
-                .inputProvider(() -> ResetPartitionsCallInput.of(options))
+                .inputProvider(() -> ResetPartitionsCallInput.of(options, 
clusterUrl.getClusterUrl()))
                 .output(spec.commandLine().getOut())
                 .errOutput(spec.commandLine().getErr())
                 .verbose(verbose)
diff --git 
a/modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/recovery/partitions/reset/ResetPartitionsMixin.java
 
b/modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/recovery/partitions/reset/ResetPartitionsMixin.java
index f1398eb55e..40c0cbde40 100644
--- 
a/modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/recovery/partitions/reset/ResetPartitionsMixin.java
+++ 
b/modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/recovery/partitions/reset/ResetPartitionsMixin.java
@@ -25,15 +25,10 @@ import static 
org.apache.ignite.internal.cli.commands.Options.Constants.RECOVERY
 import static 
org.apache.ignite.internal.cli.commands.Options.Constants.RECOVERY_ZONE_NAME_OPTION_DESC;
 
 import java.util.List;
-import org.apache.ignite.internal.cli.commands.cluster.ClusterUrlMixin;
-import picocli.CommandLine.Mixin;
 import picocli.CommandLine.Option;
 
 /** Arguments for recovery reset partitions command. */
 public class ResetPartitionsMixin {
-    @Mixin
-    private ClusterUrlMixin clusterUrl;
-
     @Option(names = RECOVERY_PARTITION_IDS_OPTION, description = 
RECOVERY_PARTITION_IDS_OPTION_DESC, split = ",")
     private List<Integer> partitionIds;
 
@@ -57,9 +52,4 @@ public class ResetPartitionsMixin {
     public List<Integer> partitionIds() {
         return partitionIds;
     }
-
-    /** Returns cluster endpoint URL. */
-    public String clusterUrl() {
-        return clusterUrl.getClusterUrl();
-    }
 }
diff --git 
a/modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/recovery/partitions/reset/ResetPartitionsReplCommand.java
 
b/modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/recovery/partitions/reset/ResetPartitionsReplCommand.java
index 87fc635050..e7efe8a1a9 100644
--- 
a/modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/recovery/partitions/reset/ResetPartitionsReplCommand.java
+++ 
b/modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/recovery/partitions/reset/ResetPartitionsReplCommand.java
@@ -21,6 +21,7 @@ import jakarta.inject.Inject;
 import org.apache.ignite.internal.cli.call.recovery.reset.ResetPartitionsCall;
 import 
org.apache.ignite.internal.cli.call.recovery.reset.ResetPartitionsCallInput;
 import org.apache.ignite.internal.cli.commands.BaseCommand;
+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;
@@ -30,6 +31,10 @@ import picocli.CommandLine.Mixin;
 /** Command to reset partitions. */
 @Command(name = "reset", description = "Resets partitions.")
 public class ResetPartitionsReplCommand extends BaseCommand implements 
Runnable {
+    /** Cluster endpoint URL option. */
+    @Mixin
+    private ClusterUrlMixin clusterUrl;
+
     @Mixin
     private ResetPartitionsMixin options;
 
@@ -41,7 +46,7 @@ public class ResetPartitionsReplCommand extends BaseCommand 
implements Runnable
 
     @Override
     public void run() {
-        question.askQuestionIfNotConnected(options.clusterUrl())
+        question.askQuestionIfNotConnected(clusterUrl.getClusterUrl())
                 .map(url -> ResetPartitionsCallInput.of(options, url))
                 .then(Flows.fromCall(call))
                 .verbose(verbose)
diff --git 
a/modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/recovery/partitions/restart/RestartPartitionsCommand.java
 
b/modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/recovery/partitions/restart/RestartPartitionsCommand.java
index b12924e3ac..accf4a4063 100644
--- 
a/modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/recovery/partitions/restart/RestartPartitionsCommand.java
+++ 
b/modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/recovery/partitions/restart/RestartPartitionsCommand.java
@@ -22,6 +22,7 @@ import java.util.concurrent.Callable;
 import 
org.apache.ignite.internal.cli.call.recovery.restart.RestartPartitionsCall;
 import 
org.apache.ignite.internal.cli.call.recovery.restart.RestartPartitionsCallInput;
 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.core.exception.handler.ClusterNotInitializedExceptionHandler;
 import picocli.CommandLine.Command;
@@ -30,6 +31,10 @@ import picocli.CommandLine.Mixin;
 /** Command to restart partitions. */
 @Command(name = "restart", description = "Restarts partitions.")
 public class RestartPartitionsCommand extends BaseCommand implements 
Callable<Integer> {
+    /** Cluster endpoint URL option. */
+    @Mixin
+    private ClusterUrlProfileMixin clusterUrl;
+
     @Mixin
     private RestartPartitionsMixin options;
 
@@ -39,7 +44,7 @@ public class RestartPartitionsCommand extends BaseCommand 
implements Callable<In
     @Override
     public Integer call() {
         return CallExecutionPipeline.builder(call)
-                .inputProvider(() -> RestartPartitionsCallInput.of(options))
+                .inputProvider(() -> RestartPartitionsCallInput.of(options, 
clusterUrl.getClusterUrl()))
                 .output(spec.commandLine().getOut())
                 .errOutput(spec.commandLine().getErr())
                 .verbose(verbose)
diff --git 
a/modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/recovery/partitions/restart/RestartPartitionsMixin.java
 
b/modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/recovery/partitions/restart/RestartPartitionsMixin.java
index 53569e8013..6527418d88 100644
--- 
a/modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/recovery/partitions/restart/RestartPartitionsMixin.java
+++ 
b/modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/recovery/partitions/restart/RestartPartitionsMixin.java
@@ -28,15 +28,10 @@ import static 
org.apache.ignite.internal.cli.commands.Options.Constants.RECOVERY
 
 import java.util.List;
 import javax.annotation.Nullable;
-import org.apache.ignite.internal.cli.commands.cluster.ClusterUrlMixin;
-import picocli.CommandLine.Mixin;
 import picocli.CommandLine.Option;
 
 /** Arguments for recovery restart partitions command. */
 public class RestartPartitionsMixin {
-    @Mixin
-    private ClusterUrlMixin clusterUrl;
-
     @Option(names = RECOVERY_PARTITION_IDS_OPTION, description = 
RECOVERY_PARTITION_IDS_OPTION_DESC, split = ",")
     private List<Integer> partitionIds;
 
@@ -70,9 +65,4 @@ public class RestartPartitionsMixin {
     public List<String> nodeNames() {
         return nodeNames;
     }
-
-    /** Returns cluster endpoint URL. */
-    public String clusterUrl() {
-        return clusterUrl.getClusterUrl();
-    }
 }
diff --git 
a/modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/recovery/partitions/restart/RestartPartitionsReplCommand.java
 
b/modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/recovery/partitions/restart/RestartPartitionsReplCommand.java
index b71c337295..d28f100e89 100644
--- 
a/modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/recovery/partitions/restart/RestartPartitionsReplCommand.java
+++ 
b/modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/recovery/partitions/restart/RestartPartitionsReplCommand.java
@@ -21,6 +21,7 @@ import jakarta.inject.Inject;
 import 
org.apache.ignite.internal.cli.call.recovery.restart.RestartPartitionsCall;
 import 
org.apache.ignite.internal.cli.call.recovery.restart.RestartPartitionsCallInput;
 import org.apache.ignite.internal.cli.commands.BaseCommand;
+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;
@@ -30,6 +31,10 @@ import picocli.CommandLine.Mixin;
 /** Command to restart partitions. */
 @Command(name = "restart", description = "Restarts partitions.")
 public class RestartPartitionsReplCommand extends BaseCommand implements 
Runnable {
+    /** Cluster endpoint URL option. */
+    @Mixin
+    private ClusterUrlMixin clusterUrl;
+
     @Mixin
     private RestartPartitionsMixin options;
 
@@ -41,7 +46,7 @@ public class RestartPartitionsReplCommand extends BaseCommand 
implements Runnabl
 
     @Override
     public void run() {
-        question.askQuestionIfNotConnected(options.clusterUrl())
+        question.askQuestionIfNotConnected(clusterUrl.getClusterUrl())
                 .map(url -> RestartPartitionsCallInput.of(options, url))
                 .then(Flows.fromCall(call))
                 .verbose(verbose)
diff --git 
a/modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/recovery/partitions/states/PartitionStatesCommand.java
 
b/modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/recovery/partitions/states/PartitionStatesCommand.java
index 08b2d4ea90..cfcceeee91 100644
--- 
a/modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/recovery/partitions/states/PartitionStatesCommand.java
+++ 
b/modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/recovery/partitions/states/PartitionStatesCommand.java
@@ -19,9 +19,10 @@ package 
org.apache.ignite.internal.cli.commands.recovery.partitions.states;
 
 import jakarta.inject.Inject;
 import java.util.concurrent.Callable;
-import org.apache.ignite.internal.cli.call.recovery.PartitionStatesCall;
-import org.apache.ignite.internal.cli.call.recovery.PartitionStatesCallInput;
+import org.apache.ignite.internal.cli.call.recovery.states.PartitionStatesCall;
+import 
org.apache.ignite.internal.cli.call.recovery.states.PartitionStatesCallInput;
 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.core.exception.handler.ClusterNotInitializedExceptionHandler;
 import org.apache.ignite.internal.cli.decorators.TableDecorator;
@@ -31,6 +32,10 @@ import picocli.CommandLine.Mixin;
 /** Command to get partition states. */
 @Command(name = "states", description = "Returns partition states.")
 public class PartitionStatesCommand extends BaseCommand implements 
Callable<Integer> {
+    /** Cluster endpoint URL option. */
+    @Mixin
+    private ClusterUrlProfileMixin clusterUrl;
+
     @Mixin
     private PartitionStatesMixin options;
 
@@ -40,7 +45,7 @@ public class PartitionStatesCommand extends BaseCommand 
implements Callable<Inte
     @Override
     public Integer call() {
         return CallExecutionPipeline.builder(call)
-                .inputProvider(() -> PartitionStatesCallInput.of(options))
+                .inputProvider(() -> PartitionStatesCallInput.of(options, 
clusterUrl.getClusterUrl()))
                 .output(spec.commandLine().getOut())
                 .errOutput(spec.commandLine().getErr())
                 .decorator(new TableDecorator(options.plain()))
diff --git 
a/modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/recovery/partitions/states/PartitionStatesMixin.java
 
b/modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/recovery/partitions/states/PartitionStatesMixin.java
index 7ce996ca82..476156e7c0 100644
--- 
a/modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/recovery/partitions/states/PartitionStatesMixin.java
+++ 
b/modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/recovery/partitions/states/PartitionStatesMixin.java
@@ -31,17 +31,11 @@ import static 
org.apache.ignite.internal.cli.commands.Options.Constants.RECOVERY
 import static 
org.apache.ignite.internal.cli.commands.Options.Constants.RECOVERY_ZONE_NAMES_OPTION_DESC;
 
 import java.util.List;
-import org.apache.ignite.internal.cli.commands.cluster.ClusterUrlMixin;
 import picocli.CommandLine.ArgGroup;
-import picocli.CommandLine.Mixin;
 import picocli.CommandLine.Option;
 
 /** Arguments for recovery partition states command. */
 public class PartitionStatesMixin {
-    /** Cluster endpoint URL option. */
-    @Mixin
-    private ClusterUrlMixin clusterUrl;
-
     /** Specific local / global states filters. */
     @ArgGroup(exclusive = true, multiplicity = "1")
     private PartitionStatesArgGroup statesArgs;
@@ -80,10 +74,6 @@ public class PartitionStatesMixin {
         return partitionIds;
     }
 
-    public String clusterUrl() {
-        return clusterUrl.getClusterUrl();
-    }
-
     static class PartitionStatesArgGroup {
         @Option(names = RECOVERY_PARTITION_GLOBAL_OPTION, description = 
RECOVERY_PARTITION_GLOBAL_OPTION_DESC)
         private boolean global;
diff --git 
a/modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/recovery/partitions/states/PartitionStatesReplCommand.java
 
b/modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/recovery/partitions/states/PartitionStatesReplCommand.java
index bbae949018..6905585508 100644
--- 
a/modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/recovery/partitions/states/PartitionStatesReplCommand.java
+++ 
b/modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/recovery/partitions/states/PartitionStatesReplCommand.java
@@ -18,9 +18,10 @@
 package org.apache.ignite.internal.cli.commands.recovery.partitions.states;
 
 import jakarta.inject.Inject;
-import org.apache.ignite.internal.cli.call.recovery.PartitionStatesCall;
-import org.apache.ignite.internal.cli.call.recovery.PartitionStatesCallInput;
+import org.apache.ignite.internal.cli.call.recovery.states.PartitionStatesCall;
+import 
org.apache.ignite.internal.cli.call.recovery.states.PartitionStatesCallInput;
 import org.apache.ignite.internal.cli.commands.BaseCommand;
+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;
@@ -31,6 +32,10 @@ import picocli.CommandLine.Mixin;
 /** Command to get partition states. */
 @Command(name = "states", description = "Returns partition states.")
 public class PartitionStatesReplCommand extends BaseCommand implements 
Runnable {
+    /** Cluster endpoint URL option. */
+    @Mixin
+    private ClusterUrlMixin clusterUrl;
+
     @Mixin
     private PartitionStatesMixin options;
 
@@ -42,7 +47,7 @@ public class PartitionStatesReplCommand extends BaseCommand 
implements Runnable
 
     @Override
     public void run() {
-        question.askQuestionIfNotConnected(options.clusterUrl())
+        question.askQuestionIfNotConnected(clusterUrl.getClusterUrl())
                 .map(url -> PartitionStatesCallInput.of(options, url))
                 .then(Flows.fromCall(call))
                 .print(new TableDecorator(options.plain()))
diff --git 
a/modules/cli/src/test/java/org/apache/ignite/internal/cli/commands/ProfileMixinTest.java
 
b/modules/cli/src/test/java/org/apache/ignite/internal/cli/commands/ProfileMixinTest.java
index 70b6b8e78d..19a8296e48 100644
--- 
a/modules/cli/src/test/java/org/apache/ignite/internal/cli/commands/ProfileMixinTest.java
+++ 
b/modules/cli/src/test/java/org/apache/ignite/internal/cli/commands/ProfileMixinTest.java
@@ -24,8 +24,12 @@ import java.util.function.Function;
 import java.util.stream.Stream;
 import org.apache.ignite.internal.cli.call.cluster.ClusterInitCall;
 import org.apache.ignite.internal.cli.call.cluster.ClusterInitCallInput;
+import org.apache.ignite.internal.cli.call.cluster.status.ClusterStatusCall;
 import 
org.apache.ignite.internal.cli.call.cluster.topology.LogicalTopologyCall;
 import 
org.apache.ignite.internal.cli.call.cluster.topology.PhysicalTopologyCall;
+import org.apache.ignite.internal.cli.call.cluster.unit.ClusterListUnitCall;
+import org.apache.ignite.internal.cli.call.cluster.unit.UndeployUnitCall;
+import org.apache.ignite.internal.cli.call.cluster.unit.UndeployUnitCallInput;
 import org.apache.ignite.internal.cli.call.configuration.ClusterConfigShowCall;
 import 
org.apache.ignite.internal.cli.call.configuration.ClusterConfigShowCallInput;
 import 
org.apache.ignite.internal.cli.call.configuration.ClusterConfigUpdateCall;
@@ -35,6 +39,14 @@ import 
org.apache.ignite.internal.cli.call.configuration.NodeConfigShowCallInput
 import org.apache.ignite.internal.cli.call.configuration.NodeConfigUpdateCall;
 import 
org.apache.ignite.internal.cli.call.configuration.NodeConfigUpdateCallInput;
 import org.apache.ignite.internal.cli.call.node.status.NodeStatusCall;
+import org.apache.ignite.internal.cli.call.node.unit.NodeListUnitCall;
+import org.apache.ignite.internal.cli.call.recovery.reset.ResetPartitionsCall;
+import 
org.apache.ignite.internal.cli.call.recovery.reset.ResetPartitionsCallInput;
+import 
org.apache.ignite.internal.cli.call.recovery.restart.RestartPartitionsCall;
+import 
org.apache.ignite.internal.cli.call.recovery.restart.RestartPartitionsCallInput;
+import org.apache.ignite.internal.cli.call.recovery.states.PartitionStatesCall;
+import 
org.apache.ignite.internal.cli.call.recovery.states.PartitionStatesCallInput;
+import org.apache.ignite.internal.cli.call.unit.ListUnitCallInput;
 import org.apache.ignite.internal.cli.core.call.Call;
 import org.apache.ignite.internal.cli.core.call.CallInput;
 import org.apache.ignite.internal.cli.core.call.UrlCallInput;
@@ -165,6 +177,12 @@ public class ProfileMixinTest extends CliCommandTestBase {
                         NodeStatusCall.class,
                         UrlCallInput.class,
                         (Function<UrlCallInput, String>) UrlCallInput::getUrl
+                ),
+                arguments(
+                        "node unit list",
+                        NodeListUnitCall.class,
+                        ListUnitCallInput.class,
+                        (Function<ListUnitCallInput, String>) 
ListUnitCallInput::url
                 )
         );
     }
@@ -200,6 +218,49 @@ public class ProfileMixinTest extends CliCommandTestBase {
                         LogicalTopologyCall.class,
                         UrlCallInput.class,
                         (Function<UrlCallInput, String>) UrlCallInput::getUrl
+                ),
+                arguments(
+                        "cluster status",
+                        ClusterStatusCall.class,
+                        UrlCallInput.class,
+                        (Function<UrlCallInput, String>) UrlCallInput::getUrl
+                ),
+                // Doesn't work because this command is special - it uses 
AsyncCall and call factory
+                // arguments(
+                //         "cluster unit deploy",
+                //         DeployUnitCall.class,
+                //         DeployUnitCallInput.class,
+                //         (Function<DeployUnitCallInput, String>) 
DeployUnitCallInput::clusterUrl
+                // ),
+                arguments(
+                        "cluster unit list",
+                        ClusterListUnitCall.class,
+                        ListUnitCallInput.class,
+                        (Function<ListUnitCallInput, String>) 
ListUnitCallInput::url
+                ),
+                arguments(
+                        "cluster unit undeploy id --version=1.0.0",
+                        UndeployUnitCall.class,
+                        UndeployUnitCallInput.class,
+                        (Function<UndeployUnitCallInput, String>) 
UndeployUnitCallInput::clusterUrl
+                ),
+                arguments(
+                        "recovery partitions states --global",
+                        PartitionStatesCall.class,
+                        PartitionStatesCallInput.class,
+                        (Function<PartitionStatesCallInput, String>) 
PartitionStatesCallInput::clusterUrl
+                ),
+                arguments(
+                        "recovery partitions reset --table test --zone test",
+                        ResetPartitionsCall.class,
+                        ResetPartitionsCallInput.class,
+                        (Function<ResetPartitionsCallInput, String>) 
ResetPartitionsCallInput::clusterUrl
+                ),
+                arguments(
+                        "recovery partitions restart --table test --zone test",
+                        RestartPartitionsCall.class,
+                        RestartPartitionsCallInput.class,
+                        (Function<RestartPartitionsCallInput, String>) 
RestartPartitionsCallInput::clusterUrl
                 )
         );
     }
diff --git 
a/modules/cli/src/test/java/org/apache/ignite/internal/cli/commands/ProfileOptionTest.java
 
b/modules/cli/src/test/java/org/apache/ignite/internal/cli/commands/ProfileOptionTest.java
new file mode 100644
index 0000000000..c08fd36dff
--- /dev/null
+++ 
b/modules/cli/src/test/java/org/apache/ignite/internal/cli/commands/ProfileOptionTest.java
@@ -0,0 +1,97 @@
+/*
+ * 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;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.everyItem;
+import static org.hamcrest.Matchers.notNullValue;
+import static org.hamcrest.Matchers.nullValue;
+
+import io.micronaut.configuration.picocli.MicronautFactory;
+import io.micronaut.context.ApplicationContext;
+import io.micronaut.test.extensions.junit5.annotation.MicronautTest;
+import jakarta.inject.Inject;
+import java.util.ArrayList;
+import java.util.List;
+import org.hamcrest.Description;
+import org.hamcrest.Matcher;
+import org.hamcrest.TypeSafeMatcher;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
+import picocli.CommandLine;
+import picocli.CommandLine.Model.OptionSpec;
+
+/**
+ * Test for the --profile option.
+ */
+@MicronautTest
+class ProfileOptionTest {
+    @Inject
+    protected ApplicationContext context;
+
+    @BeforeAll
+    static void setDumbTerminal() {
+        System.setProperty("org.jline.terminal.dumb", "true");
+    }
+
+    @Test
+    void nonReplCommands() {
+        CommandLine cmd = new CommandLine(TopLevelCliCommand.class, new 
MicronautFactory(context));
+        assertThat(subCommands(cmd), 
everyItem(profileOption(notNullValue(OptionSpec.class))));
+    }
+
+    @Test
+    void replCommands() {
+        CommandLine cmd = new CommandLine(TopLevelCliReplCommand.class, new 
MicronautFactory(context));
+        assertThat(subCommands(cmd), 
everyItem(profileOption(nullValue(OptionSpec.class))));
+    }
+
+    private static Matcher<CommandLine> profileOption(Matcher<OptionSpec> 
optionMatcher) {
+        return new TypeSafeMatcher<>() {
+            @Override
+            public void describeTo(Description description) {
+                description.appendText("a command with --profile option ")
+                        .appendDescriptionOf(optionMatcher);
+            }
+
+            @Override
+            protected boolean matchesSafely(CommandLine item) {
+                return 
optionMatcher.matches(item.getCommandSpec().findOption("--profile"));
+            }
+
+            @Override
+            protected void describeMismatchSafely(CommandLine item, 
Description mismatchDescription) {
+                
mismatchDescription.appendText(item.getCommandSpec().qualifiedName())
+                        .appendText(" has --profile option 
").appendValue(item.getCommandSpec().findOption("--profile"));
+            }
+        };
+    }
+
+    private static List<CommandLine> subCommands(CommandLine cmd) {
+        List<CommandLine> result = new ArrayList<>();
+
+        cmd.getCommandSpec().subcommands().values().forEach(subCmd -> {
+            if (subCmd.getCommandSpec().findOption("--url") != null) {
+                result.add(subCmd);
+            }
+            result.addAll(subCommands(subCmd));
+        });
+
+        return result;
+    }
+}

Reply via email to