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

shaofengshi 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 4a3e71758 [#5822] Print Help information when the help option is 
passed (#5852)
4a3e71758 is described below

commit 4a3e7175831cce2373eed9187aeb174812144d4c
Author: Lord of Abyss <103809695+abyss-l...@users.noreply.github.com>
AuthorDate: Tue Dec 17 13:40:59 2024 +0800

    [#5822] Print Help information when the help option is passed (#5852)
    
    <!--
    1. Title: [#<issue>] <type>(<scope>): <subject>
       Examples:
         - "[#123] feat(operator): support xxx"
         - "[#233] fix: check null before access result in xxx"
         - "[MINOR] refactor: fix typo in variable name"
         - "[MINOR] docs: fix typo in README"
         - "[#255] test: fix flaky test NameOfTheTest"
       Reference: https://www.conventionalcommits.org/en/v1.0.0/
    2. If the PR is unfinished, please mark this PR as draft.
    -->
    
    ### What changes were proposed in this pull request?
    
    This is a small improvement, previously, typing `entity help` will
    displays the help information for that entity. Now, the `entity --help`
    command will have the same effect.
    
    ### Why are the changes needed?
    
    Fix: #5822
    
    ### Does this PR introduce _any_ user-facing change?
    
    No
    ### How was this patch tested?
    
    ```bash
    bin/gcli.sh metalake [--help|help]
    # metalake help information
    
    bin/gcli.sh catalog [--help|help]
    # catalog help information
    
    bin/gcli.sh schema [--help|help]
    # schema help information
    
    bin/gcli.sh table [--help|help]
    # table help information
    
    bin/gcli.sh column [--help|help]
    # column help information
    
    bin/gcli.sh fileset [--help|help]
    # fileset help information
    
    bin/gcli.sh group [--help|help]
    # group help information
    
    bin/gcli.sh role [--help|help]
    # role help information
    
    bin/gcli.sh topic [--help|help]
    # topic help information
    
    bin/gcli.sh user [--help|help]
    # user help information
    
    bin/gcli.sh catalog -m demo_metalake --name Hive_catalog
    # correct details output
    ```
    
    ---------
    
    Co-authored-by: Justin Mclean <jus...@classsoftware.com>
---
 .../main/java/org/apache/gravitino/cli/Main.java   |  3 ++-
 .../java/org/apache/gravitino/cli/TestMain.java    | 31 ++++++++++++++++++++++
 2 files changed, 33 insertions(+), 1 deletion(-)

diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/Main.java 
b/clients/cli/src/main/java/org/apache/gravitino/cli/Main.java
index 49aaa9e7a..8b610511f 100644
--- a/clients/cli/src/main/java/org/apache/gravitino/cli/Main.java
+++ b/clients/cli/src/main/java/org/apache/gravitino/cli/Main.java
@@ -75,7 +75,8 @@ public class Main {
         return action;
       }
     } else if (args.length == 1) {
-      return CommandActions.DETAILS; /* Default to 'details' command. */
+      /* Default to 'details' command. */
+      return line.hasOption(GravitinoOptions.HELP) ? CommandActions.HELP : 
CommandActions.DETAILS;
     } else if (args.length == 0) {
       return null;
     }
diff --git a/clients/cli/src/test/java/org/apache/gravitino/cli/TestMain.java 
b/clients/cli/src/test/java/org/apache/gravitino/cli/TestMain.java
index 2bc05f7f3..302e8af99 100644
--- a/clients/cli/src/test/java/org/apache/gravitino/cli/TestMain.java
+++ b/clients/cli/src/test/java/org/apache/gravitino/cli/TestMain.java
@@ -144,7 +144,38 @@ public class TestMain {
     assertEquals(CommandEntities.CATALOG, entity);
   }
 
+  public void metalakeWithHelpOption() throws ParseException {
+    Options options = new GravitinoOptions().options();
+    CommandLineParser parser = new DefaultParser();
+    String[] args = {"metalake", "--help"};
+    CommandLine line = parser.parse(options, args);
+
+    assertEquals(Main.resolveEntity(line), CommandEntities.METALAKE);
+    assertEquals(Main.resolveCommand(line), CommandActions.HELP);
+  }
+
   @Test
+  public void catalogWithHelpOption() throws ParseException {
+    Options options = new GravitinoOptions().options();
+    CommandLineParser parser = new DefaultParser();
+    String[] args = {"catalog", "--help"};
+    CommandLine line = parser.parse(options, args);
+
+    assertEquals(Main.resolveEntity(line), CommandEntities.CATALOG);
+    assertEquals(Main.resolveCommand(line), CommandActions.HELP);
+  }
+
+  @Test
+  public void schemaWithHelpOption() throws ParseException {
+    Options options = new GravitinoOptions().options();
+    CommandLineParser parser = new DefaultParser();
+    String[] args = {"schema", "--help"};
+    CommandLine line = parser.parse(options, args);
+
+    assertEquals(Main.resolveEntity(line), CommandEntities.SCHEMA);
+    assertEquals(Main.resolveCommand(line), CommandActions.HELP);
+  }
+
   @SuppressWarnings("DefaultCharset")
   public void CreateTagWithNoTag() {
     String[] args = {"tag", "create", "--metalake", "metalake_test_no_tag"};

Reply via email to