PakhomovAlexander commented on code in PR #2762:
URL: https://github.com/apache/ignite-3/pull/2762#discussion_r1377504034


##########
modules/cli/src/main/java/org/apache/ignite/internal/cli/commands/questions/ConnectToClusterQuestion.java:
##########
@@ -97,22 +98,40 @@ private String sessionNodeUrl() {
     }
 
     /**
-     * Ask if the user really wants to connect if we are already connected and 
the URL is different.
+     * Ask if the user really wants to connect if we are already connected and 
the URL or authentication parameters are different.
      *
-     * @param nodeUrl Node URL.
-     * @return {@link FlowBuilder} instance which provides the node URL if we 
are not connected or connected to different URL or interrupts
-     *         if user's answer is negative.
+     * @param input Node URL and authentication parameters.
+     * @return {@link FlowBuilder} instance which provides the connect call 
input if we are not connected or user agreed to reconnect or
+     *         interrupts if user's answer is negative.
      */
-    public FlowBuilder<Void, String> askQuestionIfConnected(String nodeUrl) {
+    public FlowBuilder<Void, ConnectCallInput> 
askQuestionIfConnected(ConnectCallInput input) {
         SessionInfo sessionInfo = session.info();
-        if (sessionInfo != null && !Objects.equals(sessionInfo.nodeUrl(), 
nodeUrl)) {
-            QuestionUiComponent question = fromYesNoQuestion(
-                    "You are already connected to the %s, do you want to 
connect to the %s?",
-                    UiElements.url(sessionInfo.nodeUrl()), 
UiElements.url(nodeUrl)
-            );
-            return Flows.acceptQuestion(question, () -> nodeUrl);
+        if (sessionInfo != null) {
+            if (!Objects.equals(sessionInfo.nodeUrl(), input.url())) {
+                return Flows.acceptQuestion(fromYesNoQuestion(
+                        "You are already connected to the %s, do you want to 
connect to the %s?",
+                        UiElements.url(sessionInfo.nodeUrl()), 
UiElements.url(input.url())
+                ), () -> input);
+            }
+
+            String oldUsername = sessionInfo.username();
+            String newUsername = input.username();
+
+            if (newUsername != null) {
+                if (oldUsername != null) {
+                    return Flows.acceptQuestion(fromYesNoQuestion(
+                            "You are already connected to the %s as %s, do you 
want to connect as %s?",
+                            UiElements.url(sessionInfo.nodeUrl()), 
string(oldUsername), string(newUsername)
+                    ), () -> input);
+                } else {
+                    return Flows.acceptQuestion(fromYesNoQuestion(
+                            "You are already connected to the %s, do you want 
to connect as %s?",
+                            UiElements.url(sessionInfo.nodeUrl()), 
string(newUsername)

Review Comment:
   I think it is better to introduce `username` UI element. In the future, we 
might change the way we display usernames.



##########
modules/cli/src/test/java/org/apache/ignite/internal/cli/core/repl/completer/DynamicCompleterRegistryTest.java:
##########
@@ -324,20 +324,20 @@ void positionalParameter() {
         // Given completer for single positional parameter
         registry.register(
                 CompleterConf.builder()
-                        .command("connect") // should be real commands
+                        .command("cluster", "config", "show") // should be 
real commands
                         .singlePositionalParameter()
                         .build(),
                 words -> completer1
         );
 
         // When there is no positional argument typed
-        List<DynamicCompleter> connectCompleter = 
registry.findCompleters(words("connect"));
+        List<DynamicCompleter> connectCompleter = 
registry.findCompleters(words("cluster", "config", "show"));

Review Comment:
   configShowCompleter



##########
modules/cli/src/test/java/org/apache/ignite/internal/cli/core/repl/completer/DynamicCompletionInsiderTest.java:
##########
@@ -31,12 +31,6 @@ class DynamicCompletionInsiderTest {
 
     private static Stream<Arguments> typedWordsSource() {
         return Stream.of(
-                // connect command needs a parameter
-                Arguments.of(new String[]{"connect"}, false),

Review Comment:
   I think these test cases should not be removed but replaced with another 
command.



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

Reply via email to