diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListCatalogs.java b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListCatalogs.java index eb9c960b14e..e6aaf811ec9 100644 --- a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListCatalogs.java +++ b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListCatalogs.java @@ -49,11 +49,7 @@ public void handle() { try { GravitinoClient client = buildClient(metalake); catalogs = client.listCatalogsInfo(); - if (catalogs.length == 0) { - System.out.println("No catalogs exist."); - } else { - output(catalogs); - } + output(catalogs); } catch (NoSuchMetalakeException err) { exitWithError(ErrorMessages.UNKNOWN_METALAKE); } catch (Exception exp) { diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListMetalakes.java b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListMetalakes.java index b2388e5cd3d..ee5ac81d646 100644 --- a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListMetalakes.java +++ b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListMetalakes.java @@ -43,11 +43,7 @@ public void handle() { try { GravitinoAdminClient client = buildAdminClient(); metalakes = client.listMetalakes(); - if (metalakes.length == 0) { - System.out.println("No metalakes exist."); - } else { - output(metalakes); - } + output(metalakes); } catch (Exception exp) { exitWithError(exp.getMessage()); } diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/outputs/PlainFormat.java b/clients/cli/src/main/java/org/apache/gravitino/cli/outputs/PlainFormat.java index 6160634db90..66e616c4f78 100644 --- a/clients/cli/src/main/java/org/apache/gravitino/cli/outputs/PlainFormat.java +++ b/clients/cli/src/main/java/org/apache/gravitino/cli/outputs/PlainFormat.java @@ -50,10 +50,14 @@ public void output(Metalake metalake) { static final class MetalakesPlainFormat implements OutputFormat { @Override public void output(Metalake[] metalakes) { - List metalakeNames = - Arrays.stream(metalakes).map(Metalake::name).collect(Collectors.toList()); - String all = String.join(System.lineSeparator(), metalakeNames); - System.out.println(all); + if (metalakes.length == 0) { + System.out.println("No metalakes exist."); + } else { + List metalakeNames = + Arrays.stream(metalakes).map(Metalake::name).collect(Collectors.toList()); + String all = String.join(System.lineSeparator(), metalakeNames); + System.out.println(all); + } } } @@ -74,10 +78,14 @@ public void output(Catalog catalog) { static final class CatalogsPlainFormat implements OutputFormat { @Override public void output(Catalog[] catalogs) { - List catalogNames = - Arrays.stream(catalogs).map(Catalog::name).collect(Collectors.toList()); - String all = String.join(System.lineSeparator(), catalogNames); - System.out.println(all); + if (catalogs.length == 0) { + System.out.println("No catalogs exist."); + } else { + List catalogNames = + Arrays.stream(catalogs).map(Catalog::name).collect(Collectors.toList()); + String all = String.join(System.lineSeparator(), catalogNames); + System.out.println(all); + } } } } diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/outputs/TableFormat.java b/clients/cli/src/main/java/org/apache/gravitino/cli/outputs/TableFormat.java index 6946ad13067..c9f502069b9 100644 --- a/clients/cli/src/main/java/org/apache/gravitino/cli/outputs/TableFormat.java +++ b/clients/cli/src/main/java/org/apache/gravitino/cli/outputs/TableFormat.java @@ -56,13 +56,17 @@ public void output(Metalake metalake) { static final class MetalakesTableFormat implements OutputFormat { @Override public void output(Metalake[] metalakes) { - List headers = Collections.singletonList("metalake"); - List> rows = new ArrayList<>(); - for (int i = 0; i < metalakes.length; i++) { - rows.add(Arrays.asList(metalakes[i].name())); + if (metalakes.length == 0) { + System.out.println("No metalakes exist."); + } else { + List headers = Collections.singletonList("metalake"); + List> rows = new ArrayList<>(); + for (int i = 0; i < metalakes.length; i++) { + rows.add(Arrays.asList(metalakes[i].name())); + } + TableFormatImpl tableFormat = new TableFormatImpl(); + tableFormat.print(headers, rows); } - TableFormatImpl tableFormat = new TableFormatImpl(); - tableFormat.print(headers, rows); } } @@ -85,13 +89,17 @@ public void output(Catalog catalog) { static final class CatalogsTableFormat implements OutputFormat { @Override public void output(Catalog[] catalogs) { - List headers = Collections.singletonList("catalog"); - List> rows = new ArrayList<>(); - for (int i = 0; i < catalogs.length; i++) { - rows.add(Arrays.asList(catalogs[i].name())); + if (catalogs.length == 0) { + System.out.println("No catalogs exist."); + } else { + List headers = Collections.singletonList("catalog"); + List> rows = new ArrayList<>(); + for (int i = 0; i < catalogs.length; i++) { + rows.add(Arrays.asList(catalogs[i].name())); + } + TableFormatImpl tableFormat = new TableFormatImpl(); + tableFormat.print(headers, rows); } - TableFormatImpl tableFormat = new TableFormatImpl(); - tableFormat.print(headers, rows); } }