Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#5603] Add metalake extended help command to Gravitino CLI #5604

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -546,7 +546,8 @@ tasks.rat {
"clients/client-python/tests/unittests/htmlcov/*",
"clients/client-python/tests/integration/htmlcov/*",
"clients/client-python/docs/build",
"clients/client-python/docs/source/generated"
"clients/client-python/docs/source/generated",
"clients/cli/src/main/resources/*.txt"
)

// Add .gitignore excludes to the Apache Rat exclusion list.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
* 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";
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@

package org.apache.gravitino.cli;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.util.Map;
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.HelpFormatter;
Expand Down Expand Up @@ -175,7 +180,9 @@ public static void displayHelp(Options options) {

/** Executes the appropriate command based on the command type. */
private void executeCommand() {
if (entity.equals(CommandEntities.COLUMN)) {
if (command.equals(CommandActions.HELP)) {
handleHelpCommand();
} else if (entity.equals(CommandEntities.COLUMN)) {
handleColumnCommand();
} else if (entity.equals(CommandEntities.TABLE)) {
handleTableCommand();
Expand Down Expand Up @@ -514,6 +521,23 @@ private void handleColumnCommand() {
}
}

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());
}
}

/**
* Retrieves the Gravitinno URL from the command line options or the GRAVITINO_URL environment
* variable or the Gravitio config file.
Expand Down
40 changes: 40 additions & 0 deletions clients/cli/src/main/resources/metalake_help.txt
Original file line number Diff line number Diff line change
@@ -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
gcli metalake delete

Rename a metalake
Note:This is a potentially dangerous command to run
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
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ public void validCommands() {
assertTrue(
CommandActions.isValidCommand(CommandActions.PROPERTIES),
"PROPERTIES should be a valid command");
assertTrue(
CommandActions.isValidCommand(CommandActions.HELP), "HELP should be a valid command");
}

@Test
Expand Down
Loading