Abyss-lord commented on code in PR #6847: URL: https://github.com/apache/gravitino/pull/6847#discussion_r2030341245
########## clients/cli/src/main/java/org/apache/gravitino/cli/outputs/PlainFormat.java: ########## @@ -273,4 +281,85 @@ public String getOutput(Column[] columns) { return NEWLINE_JOINER.join(header, data.toString()); } } + + /** + * Formats tag details ({@link org.apache.gravitino.tag.Tag}) information. Output format: name, + * comment + */ + static final class TagDetailsPlainFormat extends PlainFormat<Tag> { + + /** + * Creates a new {@link TagDetailsPlainFormat}. + * + * @param context The command context. + */ + public TagDetailsPlainFormat(CommandContext context) { + super(context); + } + + /** {@inheritDoc} */ + @Override + public String getOutput(Tag tag) { + String header = COMMA_JOINER.join("name", "comment"); + String comment = tag.comment() == null ? "N/A" : tag.comment(); + + StringBuilder data = new StringBuilder(); + data.append(COMMA_JOINER.join(tag.name(), comment)); + + return NEWLINE_JOINER.join(header, data.toString()); + } + } + + /** Formats tags ({@link org.apache.gravitino.tag.Tag}) information. Output format: name */ + static final class TagListPlainFormat extends PlainFormat<Tag[]> { + + /** + * Creates a new {@link TagListPlainFormat}. + * + * @param context The command context. + */ + public TagListPlainFormat(CommandContext context) { + super(context); + } + + /** {@inheritDoc} */ + @Override + public String getOutput(Tag[] tags) { + String header = "name"; + StringBuilder data = new StringBuilder(); Review Comment: ditto. ########## clients/cli/src/main/java/org/apache/gravitino/cli/outputs/PlainFormat.java: ########## @@ -273,4 +281,85 @@ public String getOutput(Column[] columns) { return NEWLINE_JOINER.join(header, data.toString()); } } + + /** + * Formats tag details ({@link org.apache.gravitino.tag.Tag}) information. Output format: name, + * comment + */ + static final class TagDetailsPlainFormat extends PlainFormat<Tag> { + + /** + * Creates a new {@link TagDetailsPlainFormat}. + * + * @param context The command context. + */ + public TagDetailsPlainFormat(CommandContext context) { + super(context); + } + + /** {@inheritDoc} */ + @Override + public String getOutput(Tag tag) { + String header = COMMA_JOINER.join("name", "comment"); Review Comment: PlainFormat does not require a header, just but only assembles the data into String format. ########## clients/cli/src/test/java/org/apache/gravitino/cli/output/TestPlainFormat.java: ########## @@ -251,6 +253,52 @@ void testListColumnWithTableFormatAndEmptyDefaultValues() { output); } + @Test + void testTagDetailsWithPlainFormat() { + CommandContext mockContext = getMockContext(); + Tag mockTag = getMockTag("tag1", "comment for tag1"); + + PlainFormat.output(mockTag, mockContext); + String output = new String(outContent.toByteArray(), StandardCharsets.UTF_8).trim(); + Assertions.assertEquals("name,comment\n" + "tag1,comment for tag1", output); + } + + @Test + void testTagDetailsWithPlainFormatWithNullValues() { + CommandContext mockContext = getMockContext(); + Tag mockTag = mock(Tag.class); + when(mockTag.name()).thenReturn("tag1"); + when(mockTag.comment()).thenReturn(null); Review Comment: Why not use `getMockTag`. ########## clients/cli/src/test/java/org/apache/gravitino/cli/output/TestPlainFormat.java: ########## @@ -357,4 +405,13 @@ private org.apache.gravitino.rel.Column getMockColumn( return mockColumn; } + + private Tag getMockTag(String name, String comment) { + Tag mockTag = mock(Tag.class); + when(mockTag.name()).thenReturn(name); + when(mockTag.comment()).thenReturn(comment); + when(mockTag.properties()).thenReturn(ImmutableMap.of("k1", "v1", "k2", "v2")); Review Comment: Parameterize the property argument, so that you can add a test for the case where the value is null. ########## clients/cli/src/main/java/org/apache/gravitino/cli/outputs/PlainFormat.java: ########## @@ -273,4 +281,85 @@ public String getOutput(Column[] columns) { return NEWLINE_JOINER.join(header, data.toString()); } } + + /** + * Formats tag details ({@link org.apache.gravitino.tag.Tag}) information. Output format: name, + * comment + */ + static final class TagDetailsPlainFormat extends PlainFormat<Tag> { + + /** + * Creates a new {@link TagDetailsPlainFormat}. + * + * @param context The command context. + */ + public TagDetailsPlainFormat(CommandContext context) { + super(context); + } + + /** {@inheritDoc} */ + @Override + public String getOutput(Tag tag) { + String header = COMMA_JOINER.join("name", "comment"); + String comment = tag.comment() == null ? "N/A" : tag.comment(); + + StringBuilder data = new StringBuilder(); + data.append(COMMA_JOINER.join(tag.name(), comment)); + + return NEWLINE_JOINER.join(header, data.toString()); + } + } + + /** Formats tags ({@link org.apache.gravitino.tag.Tag}) information. Output format: name */ + static final class TagListPlainFormat extends PlainFormat<Tag[]> { + + /** + * Creates a new {@link TagListPlainFormat}. + * + * @param context The command context. + */ + public TagListPlainFormat(CommandContext context) { + super(context); + } + + /** {@inheritDoc} */ + @Override + public String getOutput(Tag[] tags) { + String header = "name"; + StringBuilder data = new StringBuilder(); + for (Tag tag : tags) { + data.append(tag.name()); + data.append(System.lineSeparator()); + } + + return NEWLINE_JOINER.join(header, data.toString()); + } + } + + /** Formats properties ({@link java.util.Map}) information. Output format: key, value */ + static final class PropertiesListPlainFormat extends PlainFormat<Map<?, ?>> { + + /** + * Creates a new {@link PropertiesListPlainFormat}. + * + * @param context The command context. + */ + public PropertiesListPlainFormat(CommandContext context) { + super(context); + } + + /** {@inheritDoc} */ + @Override + public String getOutput(Map<?, ?> properties) { + String header = COMMA_JOINER.join("key", "value"); Review Comment: ditto. ########## clients/cli/src/test/java/org/apache/gravitino/cli/output/TestTableFormat.java: ########## @@ -665,4 +740,13 @@ private org.apache.gravitino.rel.Column getMockColumn( return mockColumn; } + + private Tag getMockTag(String name, String comment) { + Tag mockTag = mock(Tag.class); + when(mockTag.name()).thenReturn(name); + when(mockTag.comment()).thenReturn(comment); + when(mockTag.properties()).thenReturn(ImmutableMap.of("k1", "v1", "k2", "v2")); Review Comment: ditto, plz add another test with a null property value. ########## clients/cli/src/main/java/org/apache/gravitino/cli/outputs/TableFormat.java: ########## @@ -727,4 +735,83 @@ public String getOutput(org.apache.gravitino.rel.Column[] columns) { columnComment); } } + + /** + * Formats a single {@link org.apache.gravitino.tag.Tag} instance into a two-column table display. + * Displays tag details including name and comment information. + */ + static final class TagDetailsTableFormat extends TableFormat<Tag> { + public TagDetailsTableFormat(CommandContext context) { + super(context); + } + + /** {@inheritDoc} */ + @Override + public String getOutput(Tag tag) { + Column columnName = new Column(context, "name"); + Column columnComment = new Column(context, "comment"); + + columnName.addCell(tag.name()); + columnComment.addCell( + tag.comment() == null || tag.comment().isEmpty() ? "N/A" : tag.comment()); Review Comment: You can add an overloaded method for `getComment` to LineUtil and use 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: commits-unsubscr...@gravitino.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org