-
Notifications
You must be signed in to change notification settings - Fork 379
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[#5745] feat(CLI): Table format output for ListCatalogs command #5759
[#5745] feat(CLI): Table format output for ListCatalogs command #5759
Conversation
Hi @xunliu, This PR is ready for review. Please take a look. |
@@ -33,6 +33,8 @@ public static void output(Object object) { | |||
new MetalakesStringFormat().output((Metalake[]) object); | |||
} else if (object instanceof Catalog) { | |||
new CatalogStringFormat().output((Catalog) object); | |||
} else if (object instanceof Catalog[]) { | |||
new CatalogsStringFormat().output((Catalog[]) object); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please change CatalogsStringFormat
to CatalogsPlainFormat
, and MetalakesStringFormat
, CatalogStringFormat
and other *StringFormat
class
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would probably call them CatalogPlainFormat
, MetalakePlainFormat
etc, but it is probably OK to leave the "s" in.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The CatalogPlainFormat
output Catalog
object.
The CatalogsPlainFormat
output Catalog[]
objects.
...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in this commit: f96173d
clients/cli/src/main/java/org/apache/gravitino/cli/outputs/TableFormat.java
Show resolved
Hide resolved
@@ -201,7 +201,7 @@ private void handleCatalogCommand() { | |||
String outputFormat = line.getOptionValue(GravitinoOptions.OUTPUT); | |||
|
|||
if (CommandActions.LIST.equals(command)) { | |||
newListCatalogs(url, ignore, metalake).handle(); | |||
newListCatalogs(url, ignore, metalake, outputFormat).handle(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd suggest we come up with a ListOptions wrapper for this case.
In the foreseeable future, you may want to add filter, sorting, field selector, paging options. The list of parameters to pass would grow and you have to change all these places again and again. This process is tedious and error prone.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can pass the CommondOption value in the function params.
Through CommondOption
we can get any option values.
@tengqm @justinmclean What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd suggest we don't overly generalize the options.
For example, you may want to model ListOptions
, DeleteOptions
, UpdateOptions
.
The outputFormat
, or sortBy
option can then be encapsulated into ListOptions
,
while an option like force
can be encapsulated into DeleteOptions
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would not pass the CommondOption in the function parameters, as then the command needs to know about the CLI library we use, and it makes it hard to know what options a command uses. Currently, we only have one list option and one delete option. I think we could change to a ListOptions or similar when adding extra options.
f96173d
to
e3d36c1
Compare
clients/cli/src/main/java/org/apache/gravitino/cli/GravitinoCommandLine.java
Outdated
Show resolved
Hide resolved
clients/cli/src/main/java/org/apache/gravitino/cli/GravitinoCommandLine.java
Outdated
Show resolved
Hide resolved
@@ -35,14 +36,17 @@ public class CatalogDetails extends Command { | |||
* | |||
* @param url The URL of the Gravitino server. | |||
* @param ignoreVersions If true don't check the client/server versions match. | |||
* @param outputFormat The output format. | |||
* @param listOptions The list options. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The name of this variable is confusing. You have also removed useful information i.e. that it controls the output format.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reverted to using outputFormat for @param.
@@ -168,14 +169,14 @@ protected <T extends GravitinoClientBase> Builder<T> constructClient(Builder<T> | |||
* @param <T> The type of entity. | |||
*/ | |||
protected <T> void output(T entity) { | |||
if (outputFormat == null) { | |||
if (listOptions.getOutputFormat() == null) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can listOptions be null?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The listOptions
feature is not implemented at this stage.
clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListCatalogs.java
Show resolved
Hide resolved
@@ -145,21 +146,19 @@ public void testMetalakeDetailsCommand() { | |||
} | |||
|
|||
@Test | |||
public void testCatalogDetailsCommand() { | |||
public void testCatalogListCommand() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure why this has changed from a Details command to a List command don't we want to test both?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I lost the testCatalogDetailsCommand()
during the rebase, but I have already reverted it.
2235193
to
93a464c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@waukin Thank you for your contributions.
LGTM
What changes were proposed in this pull request?
Support table format output for ListCatalogs command.
Why are the changes needed?
Issue: #5745
Does this PR introduce any user-facing change?
No.
How was this patch tested?