Skip to content

Commit

Permalink
[apache#6326] improve(CLI): Make CLI more extendable and maintainable.
Browse files Browse the repository at this point in the history
fix some error.
  • Loading branch information
Abyss-lord committed Jan 20, 2025
1 parent 57cd8dc commit ec73d1c
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ public class CatalogCommandHandler extends CommandHandler {
private final FullName name;
private final String metalake;
private String catalog;
private final String outputFormat;

/**
* Constructs a {@link CatalogCommandHandler} instance.
Expand All @@ -59,7 +58,6 @@ public CatalogCommandHandler(
this.url = getUrl(line);
this.name = new FullName(line);
this.metalake = name.getMetalakeName();
this.outputFormat = line.getOptionValue(GravitinoOptions.OUTPUT);
}

/** Handles the command execution logic based on the provided command. */
Expand Down Expand Up @@ -130,8 +128,7 @@ private void handleDetailsCommand() {
gravitinoCommandLine.newCatalogAudit(url, ignore, metalake, catalog).validate().handle();
} else {
// TODO: move this to GravitinoCommandLine class
OutputProperty property = OutputProperty.defaultOutputProperty();
property.setOutputFormat(outputFormat);
OutputProperty property = OutputProperty.fromLine(line);
gravitinoCommandLine
.newCatalogDetails(url, ignore, property, metalake, catalog)
.validate()
Expand Down Expand Up @@ -224,8 +221,7 @@ private void handleUpdateCommand() {
/** Handles the "LIST" command. */
private void handleListCommand() {
// TODO: move this to GravitinoCommandLine class
OutputProperty property = OutputProperty.defaultOutputProperty();
property.setOutputFormat(outputFormat);
OutputProperty property = OutputProperty.fromLine(line);
gravitinoCommandLine.newListCatalogs(url, ignore, property, metalake).validate().handle();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -113,22 +113,18 @@ private boolean executeCommand() {

/** Handles the "LIST" command. */
private void handleListCommand() {
String outputFormat = line.getOptionValue(GravitinoOptions.OUTPUT);
// TODO: move this to GravitinoCommandLine class
OutputProperty property = OutputProperty.defaultOutputProperty();
property.setOutputFormat(outputFormat);
OutputProperty property = OutputProperty.fromLine(line);
gravitinoCommandLine.newListMetalakes(url, ignore, property).validate().handle();
}

/** Handles the "DETAILS" command. */
private void handleDetailsCommand() {
OutputProperty property = OutputProperty.fromLine(line);
if (line.hasOption(GravitinoOptions.AUDIT)) {
gravitinoCommandLine.newMetalakeAudit(url, ignore, metalake).validate().handle();
} else {
// TODO: move this to GravitinoCommandLine class
String outputFormat = line.getOptionValue(GravitinoOptions.OUTPUT);
OutputProperty property = OutputProperty.defaultOutputProperty();
property.setOutputFormat(outputFormat);
gravitinoCommandLine.newMetalakeDetails(url, ignore, property, metalake).validate().handle();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,14 @@ public static OutputProperty defaultOutputProperty() {
*/
public static OutputProperty fromLine(CommandLine line) {
OutputProperty outputProperty = defaultOutputProperty();
String outputFormat = line.getOptionValue(GravitinoOptions.OUTPUT);
if (outputFormat != null) {
outputProperty.setOutputFormat(outputFormat);
}

if (line.hasOption(GravitinoOptions.QUIET)) {
outputProperty.setQuiet(true);
}

// TODO: implement other options.
return outputProperty;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -667,7 +667,7 @@ public String getOutput(Catalog[] catalogs) {
output("No metalakes exist.", System.err);
return null;
} else {
Column columnA = new Column("METALAKE", null, property);
Column columnA = new Column("CATALOG", null, property);
Arrays.stream(catalogs).forEach(metalake -> columnA.addCell(metalake.name()));

return getTableFormat(columnA);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ public void testCatalogListCommand() {
String output = new String(outputStream.toByteArray(), StandardCharsets.UTF_8).trim();
assertEquals(
"+---+-----------+\n"
+ "| | METALAKE |\n"
+ "| | CATALOG |\n"
+ "+---+-----------+\n"
+ "| 1 | postgres |\n"
+ "| 2 | postgres2 |\n"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,7 @@ void testCatalogsTableOutput() {
String output = new String(outContent.toByteArray(), StandardCharsets.UTF_8).trim();
Assertions.assertEquals(
"+---------------+\n"
+ "| METALAKE |\n"
+ "| CATALOG |\n"
+ "+---------------+\n"
+ "| demo_catalog1 |\n"
+ "| demo_catalog2 |\n"
Expand Down

0 comments on commit ec73d1c

Please sign in to comment.