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 8672ad73a [#5603] Add metalake extended help command to Gravitino CLI
(#5604)
8672ad73a is described below
commit 8672ad73a3168b919e4ddc04df26700d9a739b9a
Author: Justin Mclean <[email protected]>
AuthorDate: Mon Dec 2 11:55:54 2024 +1100
[#5603] Add metalake extended help command to Gravitino CLI (#5604)
### What changes were proposed in this pull request?
Add metalake extended help command to Gravitino CLI
### Why are the changes needed?
To give the use extended help via the command line.
Fix: #5603
### Does this PR introduce _any_ user-facing change?
No, other than providing extra help information.
### How was this patch tested?
Locally.
---
build.gradle.kts | 1 +
.../org/apache/gravitino/cli/CommandActions.java | 2 ++
.../apache/gravitino/cli/GravitinoCommandLine.java | 26 +++++++++++++-
clients/cli/src/main/resources/metalake_help.txt | 40 ++++++++++++++++++++++
.../apache/gravitino/cli/TestCommandActions.java | 2 ++
5 files changed, 70 insertions(+), 1 deletion(-)
diff --git a/build.gradle.kts b/build.gradle.kts
index 65187e298..49aa2fe89 100644
--- a/build.gradle.kts
+++ b/build.gradle.kts
@@ -551,6 +551,7 @@ tasks.rat {
"clients/client-python/tests/integration/htmlcov/*",
"clients/client-python/docs/build",
"clients/client-python/docs/source/generated",
+ "clients/cli/src/main/resources/*.txt",
"clients/filesystem-fuse/Cargo.lock"
)
diff --git
a/clients/cli/src/main/java/org/apache/gravitino/cli/CommandActions.java
b/clients/cli/src/main/java/org/apache/gravitino/cli/CommandActions.java
index c1b96f191..ac2b46c79 100644
--- a/clients/cli/src/main/java/org/apache/gravitino/cli/CommandActions.java
+++ b/clients/cli/src/main/java/org/apache/gravitino/cli/CommandActions.java
@@ -26,6 +26,7 @@ import java.util.HashSet;
* Gravitino CLI. It also can validate if a given command is a valid commands.
*/
public class CommandActions {
+ public static final String HELP = "help";
public static final String DETAILS = "details";
public static final String LIST = "list";
public static final String UPDATE = "update";
@@ -40,6 +41,7 @@ public class CommandActions {
private static final HashSet<String> VALID_COMMANDS = new HashSet<>();
static {
+ VALID_COMMANDS.add(HELP);
VALID_COMMANDS.add(DETAILS);
VALID_COMMANDS.add(LIST);
VALID_COMMANDS.add(UPDATE);
diff --git
a/clients/cli/src/main/java/org/apache/gravitino/cli/GravitinoCommandLine.java
b/clients/cli/src/main/java/org/apache/gravitino/cli/GravitinoCommandLine.java
index 23efe28bd..123f45fc1 100644
---
a/clients/cli/src/main/java/org/apache/gravitino/cli/GravitinoCommandLine.java
+++
b/clients/cli/src/main/java/org/apache/gravitino/cli/GravitinoCommandLine.java
@@ -20,6 +20,11 @@
package org.apache.gravitino.cli;
import com.google.common.base.Preconditions;
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.Map;
import org.apache.commons.cli.CommandLine;
@@ -112,7 +117,9 @@ public class GravitinoCommandLine extends
TestableCommandLine {
/** Executes the appropriate command based on the command type. */
private void executeCommand() {
- if (line.hasOption(GravitinoOptions.OWNER)) {
+ if (command.equals(CommandActions.HELP)) {
+ handleHelpCommand();
+ } else if (line.hasOption(GravitinoOptions.OWNER)) {
handleOwnerCommand();
} else if (entity.equals(CommandEntities.COLUMN)) {
handleColumnCommand();
@@ -466,6 +473,23 @@ public class GravitinoCommandLine extends
TestableCommandLine {
}
}
+ private void handleHelpCommand() {
+ String helpFile = entity.toLowerCase() + "_help.txt";
+
+ try (InputStream inputStream =
this.getClass().getClassLoader().getResourceAsStream(helpFile);
+ BufferedReader reader =
+ new BufferedReader(new InputStreamReader(inputStream,
StandardCharsets.UTF_8))) {
+ StringBuilder helpMessage = new StringBuilder();
+ String helpLine;
+ while ((helpLine = reader.readLine()) != null) {
+ helpMessage.append(helpLine).append(System.lineSeparator());
+ }
+ System.err.print(helpMessage.toString());
+ } catch (IOException e) {
+ System.err.println("Failed to load help message: " + e.getMessage());
+ }
+ }
+
/**
* Handles the command execution for Objects based on command type and the
command line options.
*/
diff --git a/clients/cli/src/main/resources/metalake_help.txt
b/clients/cli/src/main/resources/metalake_help.txt
new file mode 100644
index 000000000..c80d244f5
--- /dev/null
+++ b/clients/cli/src/main/resources/metalake_help.txt
@@ -0,0 +1,40 @@
+gcli metalake [details|list|create|delete|update|properties|set|remove]
+
+The Metalake for the CLI can be set using one of the following methods:
+1. Passed in on the command line via the --metalake parameter.
+2. Set via the GRAVITINO_METALAKE environment variable.
+3. Stored in the Gravitino CLI configuration file.
+
+Example Commands
+
+Show all metalakes
+gcli metalake list
+
+Show details of a metalake
+gcli metalake details
+
+Show metalake's audit information
+gcli metalake details --audit
+
+Create a metalake
+gcli metalake create --metalake my_metalake --comment "This is my metalake"
+
+Delete a metalake
+Note:This is a potentially dangerous command to run and result in data loss.
+gcli metalake delete
+
+Rename a metalake
+Note:This is a potentially dangerous command to run and may result in
unpredictable behaviour.
+gcli metalake update --rename demo
+
+Update a metalake's comment
+gcli metalake update --comment "new comment"
+
+Display the properties of a metalake
+gcli metalake properties
+
+Set a metalake's property
+gcli metalake set --property test --value value
+
+Remove a metalake's property
+gcli metalake remove --property test
diff --git
a/clients/cli/src/test/java/org/apache/gravitino/cli/TestCommandActions.java
b/clients/cli/src/test/java/org/apache/gravitino/cli/TestCommandActions.java
index 58f7f9773..895c17de7 100644
--- a/clients/cli/src/test/java/org/apache/gravitino/cli/TestCommandActions.java
+++ b/clients/cli/src/test/java/org/apache/gravitino/cli/TestCommandActions.java
@@ -44,6 +44,8 @@ public class TestCommandActions {
assertTrue(
CommandActions.isValidCommand(CommandActions.PROPERTIES),
"PROPERTIES should be a valid command");
+ assertTrue(
+ CommandActions.isValidCommand(CommandActions.HELP), "HELP should be a
valid command");
}
@Test