Skip to content

Commit

Permalink
[apache#6097] improve(CLI): Add --quiet option to the Gravitino CLI (a…
Browse files Browse the repository at this point in the history
…pache#6447)

### What changes were proposed in this pull request?

Add --quiet option to the Gravitino CLI

### Why are the changes needed?

Fix: apache#6097 

### Does this PR introduce _any_ user-facing change?

user can use --quiet option suppress the output.

### How was this patch tested?

local test

```bash
gcli tag create -m cli_demo --tag tagA tagB -i
# Tags tagA,tagB created

gcli tag create -m cli_demo --tag tagC tagD -i --quiet
# no output
```
  • Loading branch information
Abyss-lord authored and youngyjd committed Feb 14, 2025
1 parent 55c360a commit 8478f29
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public class CommandContext {
private final boolean ignoreVersions;
private final String outputFormat;
private final String url;
private final boolean quiet;
private final CommandLine line;

private String ignoreEnv;
Expand All @@ -50,6 +51,7 @@ public CommandContext(CommandLine line) {
line.hasOption(GravitinoOptions.OUTPUT)
? line.getOptionValue(GravitinoOptions.OUTPUT)
: Command.OUTPUT_FORMAT_PLAIN;
this.quiet = line.hasOption(GravitinoOptions.QUIET);

this.url = getUrl();
this.ignoreVersions = getIgnore();
Expand Down Expand Up @@ -91,6 +93,15 @@ public String outputFormat() {
return outputFormat;
}

/**
* Returns whether the command information should be suppressed.
*
* @return True if the command information should be suppressed.
*/
public boolean quiet() {
return quiet;
}

/**
* Retrieves the Gravitino URL from the command line options or the GRAVITINO_URL environment
* variable or the Gravitino config file.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public class GravitinoOptions {
public static final String PRIVILEGE = "privilege";
public static final String PROPERTIES = "properties";
public static final String PROPERTY = "property";
public static final String QUIET = "quiet";
public static final String PROVIDER = "provider";
public static final String RENAME = "rename";
public static final String ROLE = "role";
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, "quiet mode"));

// Create/update options
options.addOption(createArgOption(RENAME, "new entity name"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,10 @@ public void exitWithError(String error) {
* @param message The message to display.
*/
public void printInformation(String message) {
// so that future outoput could be suppressed
if (context.quiet()) {
return;
}

System.out.print(message);
}

Expand Down

0 comments on commit 8478f29

Please sign in to comment.