Skip to content

Commit

Permalink
[#6097] improve(CLI): Add --quiet option to the Gravition CLI
Browse files Browse the repository at this point in the history
Add --quiet option to the Gravition CLI to suppress all output except for errors.

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

fix test issues.

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

refactor Tag, Metalake and Fileset code.

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

refactor Column handler and test.

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

refactor OwnerShip handler and test.

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

refactor User handler and test.

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

refactor Role handler and test.

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

refactor Group handler and test.

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

refactor Schema handler and test.

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

refactor Topic handler and test.

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

refactor and format handlers and test cases.

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

refactor CommandHandler and TestableCommandLine.

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

refactor TestableCommandLine

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

refactor all commands.

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

Refactor Command class .

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

Add --quiet option to the Gravition CLI to suppress all output except for errors.
  • Loading branch information
Abyss-lord committed Jan 13, 2025
1 parent 2d0cda5 commit 2854dc8
Show file tree
Hide file tree
Showing 99 changed files with 1,641 additions and 649 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public class CatalogCommandHandler extends CommandHandler {
private final String metalake;
private String catalog;
private final String outputFormat;
private final boolean quiet;

/**
* Constructs a {@link CatalogCommandHandler} instance.
Expand All @@ -54,6 +55,7 @@ public CatalogCommandHandler(
this.line = line;
this.command = command;
this.ignore = ignore;
this.quiet = line.hasOption(GravitinoOptions.QUIET);

this.url = getUrl(line);
this.name = new FullName(line);
Expand Down Expand Up @@ -143,7 +145,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 +154,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 +164,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 +173,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 +195,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 @@ -36,6 +36,7 @@ public class ColumnCommandHandler extends CommandHandler {
private final String catalog;
private final String schema;
private final String table;
private final boolean quiet;
private String column;

/**
Expand All @@ -52,6 +53,7 @@ public ColumnCommandHandler(
this.line = line;
this.command = command;
this.ignore = ignore;
this.quiet = line.hasOption(GravitinoOptions.QUIET);

this.url = gravitinoCommandLine.getUrl();
this.name = new FullName(line);
Expand Down Expand Up @@ -146,6 +148,7 @@ private void handleCreateCommand() {
.newAddColumn(
url,
ignore,
quiet,
metalake,
catalog,
schema,
Expand All @@ -164,7 +167,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 +177,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 +227,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 @@ -164,6 +164,7 @@ private void handleMetalakeCommand() {
String userName = line.getOptionValue(GravitinoOptions.LOGIN);
FullName name = new FullName(line);
String outputFormat = line.getOptionValue(GravitinoOptions.OUTPUT);
boolean quiet = line.hasOption(GravitinoOptions.QUIET);

Command.setAuthenticationMode(auth, userName);

Expand All @@ -185,23 +186,23 @@ private void handleMetalakeCommand() {

case CommandActions.CREATE:
String comment = line.getOptionValue(GravitinoOptions.COMMENT);
newCreateMetalake(url, ignore, metalake, comment).validate().handle();
newCreateMetalake(url, ignore, quiet, metalake, comment).validate().handle();
break;

case CommandActions.DELETE:
boolean force = line.hasOption(GravitinoOptions.FORCE);
newDeleteMetalake(url, ignore, force, metalake).validate().handle();
newDeleteMetalake(url, ignore, quiet, force, metalake).validate().handle();
break;

case CommandActions.SET:
String property = line.getOptionValue(GravitinoOptions.PROPERTY);
String value = line.getOptionValue(GravitinoOptions.VALUE);
newSetMetalakeProperty(url, ignore, metalake, property, value).validate().handle();
newSetMetalakeProperty(url, ignore, quiet, metalake, property, value).validate().handle();
break;

case CommandActions.REMOVE:
property = line.getOptionValue(GravitinoOptions.PROPERTY);
newRemoveMetalakeProperty(url, ignore, metalake, property).validate().handle();
newRemoveMetalakeProperty(url, ignore, quiet, metalake, property).validate().handle();
break;

case CommandActions.PROPERTIES:
Expand All @@ -215,20 +216,20 @@ private void handleMetalakeCommand() {
}
if (line.hasOption(GravitinoOptions.ENABLE)) {
boolean enableAllCatalogs = line.hasOption(GravitinoOptions.ALL);
newMetalakeEnable(url, ignore, metalake, enableAllCatalogs).validate().handle();
newMetalakeEnable(url, ignore, quiet, metalake, enableAllCatalogs).validate().handle();
}
if (line.hasOption(GravitinoOptions.DISABLE)) {
newMetalakeDisable(url, ignore, metalake).validate().handle();
newMetalakeDisable(url, ignore, quiet, metalake).validate().handle();
}

if (line.hasOption(GravitinoOptions.COMMENT)) {
comment = line.getOptionValue(GravitinoOptions.COMMENT);
newUpdateMetalakeComment(url, ignore, metalake, comment).validate().handle();
newUpdateMetalakeComment(url, ignore, quiet, metalake, comment).validate().handle();
}
if (line.hasOption(GravitinoOptions.RENAME)) {
String newName = line.getOptionValue(GravitinoOptions.RENAME);
force = line.hasOption(GravitinoOptions.FORCE);
newUpdateMetalakeName(url, ignore, force, metalake, newName).validate().handle();
newUpdateMetalakeName(url, ignore, quiet, force, metalake, newName).validate().handle();
}

break;
Expand All @@ -247,6 +248,7 @@ protected void handleTagCommand() {
String userName = line.getOptionValue(GravitinoOptions.LOGIN);
FullName name = new FullName(line);
String metalake = name.getMetalakeName();
boolean quiet = line.hasOption(GravitinoOptions.QUIET);

Command.setAuthenticationMode(auth, userName);

Expand All @@ -271,21 +273,21 @@ protected void handleTagCommand() {

case CommandActions.CREATE:
String comment = line.getOptionValue(GravitinoOptions.COMMENT);
newCreateTags(url, ignore, metalake, tags, comment).validate().handle();
newCreateTags(url, ignore, quiet, metalake, tags, comment).validate().handle();
break;

case CommandActions.DELETE:
boolean forceDelete = line.hasOption(GravitinoOptions.FORCE);
newDeleteTag(url, ignore, forceDelete, metalake, tags).validate().handle();
newDeleteTag(url, ignore, quiet, forceDelete, metalake, tags).validate().handle();
break;

case CommandActions.SET:
String propertySet = line.getOptionValue(GravitinoOptions.PROPERTY);
String valueSet = line.getOptionValue(GravitinoOptions.VALUE);
if (propertySet == null && valueSet == null) {
newTagEntity(url, ignore, metalake, name, tags).validate().handle();
newTagEntity(url, ignore, quiet, metalake, name, tags).validate().handle();
} else {
newSetTagProperty(url, ignore, metalake, getOneTag(tags), propertySet, valueSet)
newSetTagProperty(url, ignore, quiet, metalake, getOneTag(tags), propertySet, valueSet)
.validate()
.handle();
}
Expand All @@ -295,15 +297,15 @@ protected void handleTagCommand() {
boolean isTag = line.hasOption(GravitinoOptions.TAG);
if (!isTag) {
boolean forceRemove = line.hasOption(GravitinoOptions.FORCE);
newRemoveAllTags(url, ignore, metalake, name, forceRemove).validate().handle();
newRemoveAllTags(url, ignore, quiet, metalake, name, forceRemove).validate().handle();
} else {
String propertyRemove = line.getOptionValue(GravitinoOptions.PROPERTY);
if (propertyRemove != null) {
newRemoveTagProperty(url, ignore, metalake, getOneTag(tags), propertyRemove)
newRemoveTagProperty(url, ignore, quiet, metalake, getOneTag(tags), propertyRemove)
.validate()
.handle();
} else {
newUntagEntity(url, ignore, metalake, name, tags).validate().handle();
newUntagEntity(url, ignore, quiet, metalake, name, tags).validate().handle();
}
}
break;
Expand All @@ -315,13 +317,15 @@ protected void handleTagCommand() {
case CommandActions.UPDATE:
if (line.hasOption(GravitinoOptions.COMMENT)) {
String updateComment = line.getOptionValue(GravitinoOptions.COMMENT);
newUpdateTagComment(url, ignore, metalake, getOneTag(tags), updateComment)
newUpdateTagComment(url, ignore, quiet, metalake, getOneTag(tags), updateComment)
.validate()
.handle();
}
if (line.hasOption(GravitinoOptions.RENAME)) {
String newName = line.getOptionValue(GravitinoOptions.RENAME);
newUpdateTagName(url, ignore, metalake, getOneTag(tags), newName).validate().handle();
newUpdateTagName(url, ignore, quiet, metalake, getOneTag(tags), newName)
.validate()
.handle();
}
break;

Expand Down Expand Up @@ -369,6 +373,7 @@ private void handleFilesetCommand() {
String metalake = name.getMetalakeName();
String catalog = name.getCatalogName();
String schema = name.getSchemaName();
boolean quiet = line.hasOption(GravitinoOptions.QUIET);

Command.setAuthenticationMode(auth, userName);

Expand Down Expand Up @@ -397,7 +402,8 @@ private void handleFilesetCommand() {
String comment = line.getOptionValue(GravitinoOptions.COMMENT);
String[] properties = line.getOptionValues(CommandActions.PROPERTIES);
Map<String, String> propertyMap = new Properties().parse(properties);
newCreateFileset(url, ignore, metalake, catalog, schema, fileset, comment, propertyMap)
newCreateFileset(
url, ignore, quiet, metalake, catalog, schema, fileset, comment, propertyMap)
.validate()
.handle();
break;
Expand All @@ -406,7 +412,7 @@ private void handleFilesetCommand() {
case CommandActions.DELETE:
{
boolean force = line.hasOption(GravitinoOptions.FORCE);
newDeleteFileset(url, ignore, force, metalake, catalog, schema, fileset)
newDeleteFileset(url, ignore, quiet, force, metalake, catalog, schema, fileset)
.validate()
.handle();
break;
Expand All @@ -416,7 +422,8 @@ private void handleFilesetCommand() {
{
String property = line.getOptionValue(GravitinoOptions.PROPERTY);
String value = line.getOptionValue(GravitinoOptions.VALUE);
newSetFilesetProperty(url, ignore, metalake, catalog, schema, fileset, property, value)
newSetFilesetProperty(
url, ignore, quiet, metalake, catalog, schema, fileset, property, value)
.validate()
.handle();
break;
Expand All @@ -425,7 +432,7 @@ private void handleFilesetCommand() {
case CommandActions.REMOVE:
{
String property = line.getOptionValue(GravitinoOptions.PROPERTY);
newRemoveFilesetProperty(url, ignore, metalake, catalog, schema, fileset, property)
newRemoveFilesetProperty(url, ignore, quiet, metalake, catalog, schema, fileset, property)
.validate()
.handle();
break;
Expand All @@ -441,13 +448,13 @@ private void handleFilesetCommand() {
{
if (line.hasOption(GravitinoOptions.COMMENT)) {
String comment = line.getOptionValue(GravitinoOptions.COMMENT);
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);
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 @@ -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(null, QUIET, "disable command output"));

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

0 comments on commit 2854dc8

Please sign in to comment.