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


##########
modules/cli/src/main/java/org/apache/ignite/cli/commands/decorators/ProfileListDecorator.java:
##########
@@ -0,0 +1,62 @@
+/*
+ * 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.cli.commands.decorators;
+
+import static org.apache.ignite.cli.core.style.AnsiStringSupport.Style;
+import static org.apache.ignite.cli.core.style.AnsiStringSupport.ansi;
+
+import java.util.stream.Collectors;
+import org.apache.ignite.cli.call.cliconfig.profile.ProfileList;
+import org.apache.ignite.cli.core.decorator.Decorator;
+import org.apache.ignite.cli.core.decorator.TerminalOutput;
+
+/**
+ * Decorator for printing {@link ProfileList}.
+ */
+public class ProfileListDecorator implements Decorator<ProfileList, 
TerminalOutput> {
+    @Override
+    public TerminalOutput decorate(ProfileList data) {
+        if (isatty()) {
+            return decorateCurrentProfileName(data);
+        } else {
+            return () -> 
data.getProfileNames().stream().collect(Collectors.joining(System.lineSeparator()));
+        }
+    }
+
+    private TerminalOutput decorateCurrentProfileName(ProfileList data) {
+        String currentProfileName = data.getCurrentProfileName();
+        return () -> data.getProfileNames().stream()
+                .map(p -> {
+                    if (p.equals(currentProfileName)) {
+                        return ansi(Style.BOLD.mark("* " + p));

Review Comment:
   In case we merge the UI Components it is better to use them here.



##########
modules/cli/src/test/java/org/apache/ignite/cli/commands/cliconfig/CliConfigProfileListCommandTest.java:
##########
@@ -0,0 +1,67 @@
+/*
+ * 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.cli.commands.cliconfig;
+
+import static org.junit.jupiter.api.Assertions.assertAll;
+
+import 
org.apache.ignite.cli.commands.cliconfig.profile.CliConfigProfileListCommand;
+import org.apache.ignite.cli.config.ini.IniConfigManager;
+import org.junit.jupiter.api.Test;
+
+class CliConfigProfileListCommandTest extends CliConfigCommandTestBase {
+    @Override
+    protected Class<?> getCommandClass() {
+        return CliConfigProfileListCommand.class;
+    }
+
+    @Test
+    public void testWithDefaultProfile() {
+        execute();
+
+        String expectedResult = "owner" + System.lineSeparator()
+                + "database" + System.lineSeparator();
+        assertAll(
+                () -> assertOutputIs(expectedResult),
+                this::assertErrOutputIsEmpty
+        );
+    }
+
+    @Test
+    public void testSingleProfile() {
+        configManagerProvider.configManager = new 
IniConfigManager(TestConfigManagerHelper.createClusterUrlNonDefault());
+        execute();
+
+        String expectedResult = "default" + System.lineSeparator();

Review Comment:
   Could you rename `default` to `nonDefault`?



##########
modules/cli/src/test/java/org/apache/ignite/cli/commands/cliconfig/CliConfigProfileListCommandTest.java:
##########
@@ -0,0 +1,67 @@
+/*
+ * 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.cli.commands.cliconfig;
+
+import static org.junit.jupiter.api.Assertions.assertAll;
+
+import 
org.apache.ignite.cli.commands.cliconfig.profile.CliConfigProfileListCommand;
+import org.apache.ignite.cli.config.ini.IniConfigManager;
+import org.junit.jupiter.api.Test;
+
+class CliConfigProfileListCommandTest extends CliConfigCommandTestBase {
+    @Override
+    protected Class<?> getCommandClass() {
+        return CliConfigProfileListCommand.class;
+    }
+
+    @Test
+    public void testWithDefaultProfile() {
+        execute();
+
+        String expectedResult = "owner" + System.lineSeparator()
+                + "database" + System.lineSeparator();
+        assertAll(
+                () -> assertOutputIs(expectedResult),
+                this::assertErrOutputIsEmpty
+        );
+    }
+
+    @Test
+    public void testSingleProfile() {
+        configManagerProvider.configManager = new 
IniConfigManager(TestConfigManagerHelper.createClusterUrlNonDefault());
+        execute();
+
+        String expectedResult = "default" + System.lineSeparator();

Review Comment:
   As far as I can see we set up non default profile but check the default one.



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