justinmclean commented on code in PR #6483:
URL: https://github.com/apache/gravitino/pull/6483#discussion_r1962775987


##########
clients/cli/src/main/java/org/apache/gravitino/cli/outputs/PlainFormat.java:
##########
@@ -23,68 +23,118 @@
 import java.util.stream.Collectors;
 import org.apache.gravitino.Catalog;
 import org.apache.gravitino.Metalake;
+import org.apache.gravitino.cli.CommandContext;
 
 /** Plain format to print a pretty string to standard out. */
-public class PlainFormat {
-  public static void output(Object object) {
-    if (object instanceof Metalake) {
-      new MetalakePlainFormat().output((Metalake) object);
-    } else if (object instanceof Metalake[]) {
-      new MetalakesPlainFormat().output((Metalake[]) object);
-    } else if (object instanceof Catalog) {
-      new CatalogPlainFormat().output((Catalog) object);
-    } else if (object instanceof Catalog[]) {
-      new CatalogsPlainFormat().output((Catalog[]) object);
+public abstract class PlainFormat<T> extends BaseOutputFormat<T> {
+
+  /**
+   * Routes the object to its appropriate formatter and outputs the formatted 
result. Creates a new
+   * formatter instance for the given object type and delegates the formatting.
+   *
+   * @param entity The object to format
+   * @param context The command context
+   * @throws IllegalArgumentException if the object type is not supported
+   */
+  public static void output(Object entity, CommandContext context) {
+    if (entity instanceof Metalake) {
+      new MetalakePlainFormat(context).output((Metalake) entity);
+    } else if (entity instanceof Metalake[]) {
+      new MetalakeListPlainFormat(context).output((Metalake[]) entity);
+    } else if (entity instanceof Catalog) {
+      new CatalogPlainFormat(context).output((Catalog) entity);
+    } else if (entity instanceof Catalog[]) {
+      new CatalogListPlainFormat(context).output((Catalog[]) entity);
     } else {
       throw new IllegalArgumentException("Unsupported object type");
     }
   }
 
-  static final class MetalakePlainFormat implements OutputFormat<Metalake> {
+  /**
+   * Creates a new {@link PlainFormat} with the specified output properties.
+   *
+   * @param context The command context.
+   */
+  public PlainFormat(CommandContext context) {
+    super(context);
+  }
+
+  /**
+   * Formats a single {@link Metalake} instance as a comma-separated string. 
Output format: name,
+   * comment
+   */
+  static final class MetalakePlainFormat extends PlainFormat<Metalake> {
+
+    public MetalakePlainFormat(CommandContext context) {
+      super(context);
+    }
+
+    /** {@inheritDoc} */
     @Override
-    public void output(Metalake metalake) {
-      System.out.println(metalake.name() + "," + metalake.comment());
+    public String getOutput(Metalake metalake) {
+      return COMMA_JOINER.join(metalake.name(), metalake.comment());
     }
   }
 
-  static final class MetalakesPlainFormat implements OutputFormat<Metalake[]> {
+  /**
+   * Formats an array of Metalakes, outputting one name per line. Returns null 
if the array is empty
+   * or null.
+   */
+  static final class MetalakeListPlainFormat extends PlainFormat<Metalake[]> {
+
+    public MetalakeListPlainFormat(CommandContext context) {
+      super(context);
+    }
+
+    /** {@inheritDoc} */
     @Override
-    public void output(Metalake[] metalakes) {
-      if (metalakes.length == 0) {
-        System.out.println("No metalakes exist.");
+    public String getOutput(Metalake[] metalakes) {
+      if (metalakes == null || metalakes.length == 0) {
+        return null;
       } else {
         List<String> metalakeNames =
             
Arrays.stream(metalakes).map(Metalake::name).collect(Collectors.toList());
-        String all = String.join(System.lineSeparator(), metalakeNames);
-        System.out.println(all);
+        return NEWLINE_JOINER.join(metalakeNames);
       }
     }
   }
 
-  static final class CatalogPlainFormat implements OutputFormat<Catalog> {
+  /**
+   * Formats a single {@link Catalog} instance as a comma-separated string. 
Output format: name,
+   * type, provider, comment
+   */
+  static final class CatalogPlainFormat extends PlainFormat<Catalog> {
+    public CatalogPlainFormat(CommandContext context) {
+      super(context);
+    }
+
+    /** {@inheritDoc} */
     @Override
-    public void output(Catalog catalog) {
-      System.out.println(
-          catalog.name()
-              + ","
-              + catalog.type()
-              + ","
-              + catalog.provider()
-              + ","
-              + catalog.comment());
+    public String getOutput(Catalog catalog) {
+      return COMMA_JOINER.join(
+          catalog.name(), catalog.type(), catalog.provider(), 
catalog.comment());
     }
   }
 
-  static final class CatalogsPlainFormat implements OutputFormat<Catalog[]> {
+  /**
+   * Formats an array of Catalogs, outputting one name per line. Returns null 
if the array is empty
+   * or null.
+   */
+  static final class CatalogListPlainFormat extends PlainFormat<Catalog[]> {
+    public CatalogListPlainFormat(CommandContext context) {
+      super(context);
+    }
+
+    /** {@inheritDoc} */
     @Override
-    public void output(Catalog[] catalogs) {
-      if (catalogs.length == 0) {
-        System.out.println("No catalogs exist.");
+    public String getOutput(Catalog[] catalogs) {
+      if (catalogs == null || catalogs.length == 0) {
+        output("No catalogs exists.", System.err);

Review Comment:
   This should be an informational message, is it?



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