This is an automated email from the ASF dual-hosted git repository.

jmclean pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/gravitino.git


The following commit(s) were added to refs/heads/main by this push:
     new cdc5f8fdc0 [#6097] improve(CLI): Add --quiet option to the Gravitino 
CLI (#6447)
cdc5f8fdc0 is described below

commit cdc5f8fdc098d36246a103806f6d5191c2b2c4f2
Author: Lord of Abyss <103809695+abyss-l...@users.noreply.github.com>
AuthorDate: Thu Feb 13 16:10:11 2025 +0800

    [#6097] improve(CLI): Add --quiet option to the Gravitino CLI (#6447)
    
    ### What changes were proposed in this pull request?
    
    Add --quiet option to the Gravitino CLI
    
    ### Why are the changes needed?
    
    Fix: #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
    ```
---
 .../main/java/org/apache/gravitino/cli/CommandContext.java    | 11 +++++++++++
 .../main/java/org/apache/gravitino/cli/GravitinoOptions.java  |  2 ++
 .../main/java/org/apache/gravitino/cli/commands/Command.java  |  5 ++++-
 3 files changed, 17 insertions(+), 1 deletion(-)

diff --git 
a/clients/cli/src/main/java/org/apache/gravitino/cli/CommandContext.java 
b/clients/cli/src/main/java/org/apache/gravitino/cli/CommandContext.java
index fc713ba577..b684ede48f 100644
--- a/clients/cli/src/main/java/org/apache/gravitino/cli/CommandContext.java
+++ b/clients/cli/src/main/java/org/apache/gravitino/cli/CommandContext.java
@@ -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;
@@ -50,6 +51,7 @@ public class CommandContext {
         line.hasOption(GravitinoOptions.OUTPUT)
             ? line.getOptionValue(GravitinoOptions.OUTPUT)
             : Command.OUTPUT_FORMAT_PLAIN;
+    this.quiet = line.hasOption(GravitinoOptions.QUIET);
 
     this.url = getUrl();
     this.ignoreVersions = getIgnore();
@@ -91,6 +93,15 @@ public class CommandContext {
     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.
diff --git 
a/clients/cli/src/main/java/org/apache/gravitino/cli/GravitinoOptions.java 
b/clients/cli/src/main/java/org/apache/gravitino/cli/GravitinoOptions.java
index 47f9914233..9d304c8775 100644
--- a/clients/cli/src/main/java/org/apache/gravitino/cli/GravitinoOptions.java
+++ b/clients/cli/src/main/java/org/apache/gravitino/cli/GravitinoOptions.java
@@ -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";
@@ -91,6 +92,7 @@ public class GravitinoOptions {
     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"));
diff --git 
a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/Command.java 
b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/Command.java
index c9d758c17a..6ecef9278b 100644
--- a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/Command.java
+++ b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/Command.java
@@ -85,7 +85,10 @@ public abstract class Command {
    * @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);
   }
 

Reply via email to