justinmclean commented on code in PR #6483: URL: https://github.com/apache/gravitino/pull/6483#discussion_r1962775395
########## 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; Review Comment: Does it still output "No metalakes exist." if none exist? -- 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: commits-unsubscr...@gravitino.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org