Skip to content
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

[#6097] improve(CLI): Add --quiet option to the Gravition CLI #6198

Open
wants to merge 15 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public class CatalogCommandHandler extends CommandHandler {
private final CommandLine line;
private final String command;
private final boolean ignore;
private final boolean quiet;
private final String url;
private final FullName name;
private final String metalake;
Expand All @@ -47,13 +48,19 @@ public class CatalogCommandHandler extends CommandHandler {
* @param line The command line arguments.
* @param command The command to execute.
* @param ignore Ignore server version mismatch.
* @param quiet Suppress output.
*/
public CatalogCommandHandler(
GravitinoCommandLine gravitinoCommandLine, CommandLine line, String command, boolean ignore) {
GravitinoCommandLine gravitinoCommandLine,
CommandLine line,
String command,
boolean ignore,
boolean quiet) {
this.gravitinoCommandLine = gravitinoCommandLine;
this.line = line;
this.command = command;
this.ignore = ignore;
this.quiet = quiet;

this.url = getUrl(line);
this.name = new FullName(line);
Expand Down Expand Up @@ -143,7 +150,7 @@ private void handleCreateCommand() {

Map<String, String> propertyMap = new Properties().parse(properties);
gravitinoCommandLine
.newCreateCatalog(url, ignore, metalake, catalog, provider, comment, propertyMap)
.newCreateCatalog(url, ignore, quiet, metalake, catalog, provider, comment, propertyMap)
.validate()
.handle();
}
Expand All @@ -152,7 +159,7 @@ private void handleCreateCommand() {
private void handleDeleteCommand() {
boolean force = line.hasOption(GravitinoOptions.FORCE);
gravitinoCommandLine
.newDeleteCatalog(url, ignore, force, metalake, catalog)
.newDeleteCatalog(url, ignore, quiet, force, metalake, catalog)
.validate()
.handle();
}
Expand All @@ -162,7 +169,7 @@ private void handleSetCommand() {
String property = line.getOptionValue(GravitinoOptions.PROPERTY);
String value = line.getOptionValue(GravitinoOptions.VALUE);
gravitinoCommandLine
.newSetCatalogProperty(url, ignore, metalake, catalog, property, value)
.newSetCatalogProperty(url, ignore, quiet, metalake, catalog, property, value)
.validate()
.handle();
}
Expand All @@ -171,7 +178,7 @@ private void handleSetCommand() {
private void handleRemoveCommand() {
String property = line.getOptionValue(GravitinoOptions.PROPERTY);
gravitinoCommandLine
.newRemoveCatalogProperty(url, ignore, metalake, catalog, property)
.newRemoveCatalogProperty(url, ignore, quiet, metalake, catalog, property)
.validate()
.handle();
}
Expand All @@ -193,25 +200,28 @@ private void handleUpdateCommand() {
if (line.hasOption(GravitinoOptions.ENABLE)) {
boolean enableMetalake = line.hasOption(GravitinoOptions.ALL);
gravitinoCommandLine
.newCatalogEnable(url, ignore, metalake, catalog, enableMetalake)
.newCatalogEnable(url, ignore, quiet, metalake, catalog, enableMetalake)
.validate()
.handle();
}
if (line.hasOption(GravitinoOptions.DISABLE)) {
gravitinoCommandLine.newCatalogDisable(url, ignore, metalake, catalog).validate().handle();
gravitinoCommandLine
.newCatalogDisable(url, ignore, quiet, metalake, catalog)
.validate()
.handle();
}

if (line.hasOption(GravitinoOptions.COMMENT)) {
String updateComment = line.getOptionValue(GravitinoOptions.COMMENT);
gravitinoCommandLine
.newUpdateCatalogComment(url, ignore, metalake, catalog, updateComment)
.newUpdateCatalogComment(url, ignore, quiet, metalake, catalog, updateComment)
.validate()
.handle();
}
if (line.hasOption(GravitinoOptions.RENAME)) {
String newName = line.getOptionValue(GravitinoOptions.RENAME);
gravitinoCommandLine
.newUpdateCatalogName(url, ignore, metalake, catalog, newName)
.newUpdateCatalogName(url, ignore, quiet, metalake, catalog, newName)
.validate()
.handle();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public class ColumnCommandHandler extends CommandHandler {
private final CommandLine line;
private final String command;
private final boolean ignore;
private final boolean quiet;
private final String url;
private final FullName name;
private final String metalake;
Expand All @@ -45,13 +46,19 @@ public class ColumnCommandHandler extends CommandHandler {
* @param line The command line arguments.
* @param command The command to execute.
* @param ignore Ignore server version mismatch.
* @param quiet suppress output.
*/
public ColumnCommandHandler(
GravitinoCommandLine gravitinoCommandLine, CommandLine line, String command, boolean ignore) {
GravitinoCommandLine gravitinoCommandLine,
CommandLine line,
String command,
boolean ignore,
boolean quiet) {
this.gravitinoCommandLine = gravitinoCommandLine;
this.line = line;
this.command = command;
this.ignore = ignore;
this.quiet = quiet;

this.url = gravitinoCommandLine.getUrl();
this.name = new FullName(line);
Expand Down Expand Up @@ -146,6 +153,7 @@ private void handleCreateCommand() {
.newAddColumn(
url,
ignore,
quiet,
metalake,
catalog,
schema,
Expand All @@ -164,7 +172,7 @@ private void handleCreateCommand() {
/** Handles the "DELETE" command. */
private void handleDeleteCommand() {
gravitinoCommandLine
.newDeleteColumn(url, ignore, metalake, catalog, schema, table, column)
.newDeleteColumn(url, ignore, quiet, metalake, catalog, schema, table, column)
.validate()
.handle();
}
Expand All @@ -174,44 +182,48 @@ private void handleUpdateCommand() {
if (line.hasOption(GravitinoOptions.COMMENT)) {
String comment = line.getOptionValue(GravitinoOptions.COMMENT);
gravitinoCommandLine
.newUpdateColumnComment(url, ignore, metalake, catalog, schema, table, column, comment)
.newUpdateColumnComment(
url, ignore, quiet, metalake, catalog, schema, table, column, comment)
.validate()
.handle();
}
if (line.hasOption(GravitinoOptions.RENAME)) {
String newName = line.getOptionValue(GravitinoOptions.RENAME);
gravitinoCommandLine
.newUpdateColumnName(url, ignore, metalake, catalog, schema, table, column, newName)
.newUpdateColumnName(
url, ignore, quiet, metalake, catalog, schema, table, column, newName)
.validate()
.handle();
}
if (line.hasOption(GravitinoOptions.DATATYPE) && !line.hasOption(GravitinoOptions.DEFAULT)) {
String datatype = line.getOptionValue(GravitinoOptions.DATATYPE);
gravitinoCommandLine
.newUpdateColumnDatatype(url, ignore, metalake, catalog, schema, table, column, datatype)
.newUpdateColumnDatatype(
url, ignore, quiet, metalake, catalog, schema, table, column, datatype)
.validate()
.handle();
}
if (line.hasOption(GravitinoOptions.POSITION)) {
String position = line.getOptionValue(GravitinoOptions.POSITION);
gravitinoCommandLine
.newUpdateColumnPosition(url, ignore, metalake, catalog, schema, table, column, position)
.newUpdateColumnPosition(
url, ignore, quiet, metalake, catalog, schema, table, column, position)
.validate()
.handle();
}
if (line.hasOption(GravitinoOptions.NULL)) {
boolean nullable = line.getOptionValue(GravitinoOptions.NULL).equals("true");
gravitinoCommandLine
.newUpdateColumnNullability(
url, ignore, metalake, catalog, schema, table, column, nullable)
url, ignore, quiet, metalake, catalog, schema, table, column, nullable)
.validate()
.handle();
}
if (line.hasOption(GravitinoOptions.AUTO)) {
boolean autoIncrement = line.getOptionValue(GravitinoOptions.AUTO).equals("true");
gravitinoCommandLine
.newUpdateColumnAutoIncrement(
url, ignore, metalake, catalog, schema, table, column, autoIncrement)
url, ignore, quiet, metalake, catalog, schema, table, column, autoIncrement)
.validate()
.handle();
}
Expand All @@ -220,7 +232,7 @@ private void handleUpdateCommand() {
String dataType = line.getOptionValue(GravitinoOptions.DATATYPE);
gravitinoCommandLine
.newUpdateColumnDefault(
url, ignore, metalake, catalog, schema, table, column, defaultValue, dataType)
url, ignore, quiet, metalake, catalog, schema, table, column, defaultValue, dataType)
.validate()
.handle();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ public class CommandEntities {
VALID_ENTITIES.add(TOPIC);
VALID_ENTITIES.add(FILESET);
VALID_ENTITIES.add(ROLE);
VALID_ENTITIES.add(MODEL);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public class FilesetCommandHandler extends CommandHandler {
private final CommandLine line;
private final String command;
private final boolean ignore;
private final boolean quiet;
private final String url;
private final FullName name;
private final String metalake;
Expand All @@ -46,13 +47,19 @@ public class FilesetCommandHandler extends CommandHandler {
* @param line The command line arguments.
* @param command The command to execute.
* @param ignore Ignore server version mismatch.
* @param quiet Suppress output.
*/
public FilesetCommandHandler(
GravitinoCommandLine gravitinoCommandLine, CommandLine line, String command, boolean ignore) {
GravitinoCommandLine gravitinoCommandLine,
CommandLine line,
String command,
boolean ignore,
boolean quiet) {
this.gravitinoCommandLine = gravitinoCommandLine;
this.line = line;
this.command = command;
this.ignore = ignore;
this.quiet = quiet;

this.url = gravitinoCommandLine.getUrl();
this.name = new FullName(line);
Expand Down Expand Up @@ -141,7 +148,8 @@ private void handleCreateCommand() {
String[] properties = line.getOptionValues(CommandActions.PROPERTIES);
Map<String, String> propertyMap = new Properties().parse(properties);
gravitinoCommandLine
.newCreateFileset(url, ignore, metalake, catalog, schema, fileset, comment, propertyMap)
.newCreateFileset(
url, ignore, quiet, metalake, catalog, schema, fileset, comment, propertyMap)
.validate()
.handle();
}
Expand All @@ -150,7 +158,7 @@ private void handleCreateCommand() {
private void handleDeleteCommand() {
boolean force = line.hasOption(GravitinoOptions.FORCE);
gravitinoCommandLine
.newDeleteFileset(url, ignore, force, metalake, catalog, schema, fileset)
.newDeleteFileset(url, ignore, quiet, force, metalake, catalog, schema, fileset)
.validate()
.handle();
}
Expand All @@ -160,7 +168,8 @@ private void handleSetCommand() {
String property = line.getOptionValue(GravitinoOptions.PROPERTY);
String value = line.getOptionValue(GravitinoOptions.VALUE);
gravitinoCommandLine
.newSetFilesetProperty(url, ignore, metalake, catalog, schema, fileset, property, value)
.newSetFilesetProperty(
url, ignore, quiet, metalake, catalog, schema, fileset, property, value)
.validate()
.handle();
}
Expand All @@ -169,7 +178,7 @@ private void handleSetCommand() {
private void handleRemoveCommand() {
String property = line.getOptionValue(GravitinoOptions.PROPERTY);
gravitinoCommandLine
.newRemoveFilesetProperty(url, ignore, metalake, catalog, schema, fileset, property)
.newRemoveFilesetProperty(url, ignore, quiet, metalake, catalog, schema, fileset, property)
.validate()
.handle();
}
Expand All @@ -195,14 +204,14 @@ private void handleUpdateCommand() {
if (line.hasOption(GravitinoOptions.COMMENT)) {
String comment = line.getOptionValue(GravitinoOptions.COMMENT);
gravitinoCommandLine
.newUpdateFilesetComment(url, ignore, metalake, catalog, schema, fileset, comment)
.newUpdateFilesetComment(url, ignore, quiet, metalake, catalog, schema, fileset, comment)
.validate()
.handle();
}
if (line.hasOption(GravitinoOptions.RENAME)) {
String newName = line.getOptionValue(GravitinoOptions.RENAME);
gravitinoCommandLine
.newUpdateFilesetName(url, ignore, metalake, catalog, schema, fileset, newName)
.newUpdateFilesetName(url, ignore, quiet, metalake, catalog, schema, fileset, newName)
.validate()
.handle();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,34 +120,35 @@ public static void displayHelp(Options options) {

/** Executes the appropriate command based on the command type. */
private void executeCommand() {
boolean quiet = line.hasOption(GravitinoOptions.QUIET);
if (CommandActions.HELP.equals(command)) {
handleHelpCommand();
} else if (line.hasOption(GravitinoOptions.OWNER)) {
new OwnerCommandHandler(this, line, command, ignore, entity).handle();
new OwnerCommandHandler(this, line, command, ignore, quiet, entity).handle();
} else if (entity.equals(CommandEntities.COLUMN)) {
new ColumnCommandHandler(this, line, command, ignore).handle();
new ColumnCommandHandler(this, line, command, ignore, quiet).handle();
} else if (entity.equals(CommandEntities.TABLE)) {
new TableCommandHandler(this, line, command, ignore).handle();
new TableCommandHandler(this, line, command, ignore, quiet).handle();
} else if (entity.equals(CommandEntities.SCHEMA)) {
new SchemaCommandHandler(this, line, command, ignore).handle();
new SchemaCommandHandler(this, line, command, ignore, quiet).handle();
} else if (entity.equals(CommandEntities.CATALOG)) {
new CatalogCommandHandler(this, line, command, ignore).handle();
new CatalogCommandHandler(this, line, command, ignore, quiet).handle();
} else if (entity.equals(CommandEntities.METALAKE)) {
new MetalakeCommandHandler(this, line, command, ignore).handle();
new MetalakeCommandHandler(this, line, command, ignore, quiet).handle();
} else if (entity.equals(CommandEntities.TOPIC)) {
new TopicCommandHandler(this, line, command, ignore).handle();
new TopicCommandHandler(this, line, command, ignore, quiet).handle();
} else if (entity.equals(CommandEntities.FILESET)) {
new FilesetCommandHandler(this, line, command, ignore).handle();
new FilesetCommandHandler(this, line, command, ignore, quiet).handle();
} else if (entity.equals(CommandEntities.USER)) {
new UserCommandHandler(this, line, command, ignore).handle();
new UserCommandHandler(this, line, command, ignore, quiet).handle();
} else if (entity.equals(CommandEntities.GROUP)) {
new GroupCommandHandler(this, line, command, ignore).handle();
new GroupCommandHandler(this, line, command, ignore, quiet).handle();
} else if (entity.equals(CommandEntities.TAG)) {
new TagCommandHandler(this, line, command, ignore).handle();
new TagCommandHandler(this, line, command, ignore, quiet).handle();
} else if (entity.equals(CommandEntities.ROLE)) {
new RoleCommandHandler(this, line, command, ignore).handle();
new RoleCommandHandler(this, line, command, ignore, quiet).handle();
} else if (entity.equals(CommandEntities.MODEL)) {
new ModelCommandHandler(this, line, command, ignore).handle();
new ModelCommandHandler(this, line, command, ignore, quiet).handle();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ public class GravitinoOptions {
public static final String DISABLE = "disable";
public static final String ALIAS = "alias";
public static final String URI = "uri";
public static final String QUIET = "quiet";

/**
* Builds and returns the CLI options for Gravitino.
Expand Down Expand Up @@ -91,6 +92,7 @@ public Options options() {
options.addOption(createSimpleOption(null, SORTORDER, "display sortorder information"));
options.addOption(createSimpleOption(null, ENABLE, "enable entities"));
options.addOption(createSimpleOption(null, DISABLE, "disable entities"));
options.addOption(createSimpleOption("q", QUIET, "disable command output"));

// Create/update options
options.addOption(createArgOption(RENAME, "new entity name"));
Expand Down
Loading
Loading