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 11eceb97f [ #4943] Update from feedback on Gravitino CLI demo (#5497)
11eceb97f is described below

commit 11eceb97f7d8f769a6b377fe2da7447d58dcaaac
Author: Justin Mclean <[email protected]>
AuthorDate: Tue Nov 12 13:28:34 2024 +1100

    [ #4943] Update from feedback on Gravitino CLI demo (#5497)
    
    ### What changes were proposed in this pull request?
    
    Feedback arising from the demo including:
    - asking users are you sure to any dangerous operations
    - adding a --force option
    - remove --metalake from examples
    - update documentation
    
    ### Why are the changes needed?
    
    Update from demo.
    
    Fix: #5537
    
    ### Does this PR introduce _any_ user-facing change?
    
    Delete commands and rename metalake now ask the user are you sure.
    
    ### How was this patch tested?
    
    Locally.
---
 .../java/org/apache/gravitino/cli/AreYouSure.java  |  47 ++++++++
 .../apache/gravitino/cli/GravitinoCommandLine.java |  26 ++--
 .../org/apache/gravitino/cli/GravitinoOptions.java |   4 +
 .../gravitino/cli/commands/DeleteCatalog.java      |  11 +-
 .../apache/gravitino/cli/commands/DeleteGroup.java |  11 +-
 .../gravitino/cli/commands/DeleteMetalake.java     |  11 +-
 .../gravitino/cli/commands/DeleteSchema.java       |  15 ++-
 .../apache/gravitino/cli/commands/DeleteTable.java |   9 ++
 .../apache/gravitino/cli/commands/DeleteTag.java   |  12 +-
 .../apache/gravitino/cli/commands/DeleteUser.java  |  11 +-
 .../gravitino/cli/commands/UpdateMetalakeName.java |  12 +-
 docs/cli.md                                        | 132 +++++++++++----------
 12 files changed, 222 insertions(+), 79 deletions(-)

diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/AreYouSure.java 
b/clients/cli/src/main/java/org/apache/gravitino/cli/AreYouSure.java
new file mode 100644
index 000000000..a0893dbad
--- /dev/null
+++ b/clients/cli/src/main/java/org/apache/gravitino/cli/AreYouSure.java
@@ -0,0 +1,47 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.gravitino.cli;
+
+import java.nio.charset.StandardCharsets;
+import java.util.Scanner;
+
+/* Ask are you sure you want to do this? */
+public class AreYouSure {
+
+  /**
+   * Prompts the user with a confirmation message to confirm an action.
+   *
+   * @param force if {@code true}, skips user confirmation and proceeds.
+   * @return {@code true} if the action is to continue {@code false} otherwise.
+   */
+  public static boolean really(boolean force) {
+    Scanner scanner = new Scanner(System.in, StandardCharsets.UTF_8.name());
+
+    /* force option for scripting */
+    if (force) {
+      return true;
+    }
+
+    System.out.println(
+        "This command could result in data loss or other issues. Are you sure 
you want to do this? (Y/N)");
+    String answer = scanner.next();
+    return answer.equals("Y");
+  }
+}
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 7e95d59fc..b544a6b80 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
@@ -100,7 +100,7 @@ public class GravitinoCommandLine {
    *
    * @param line Parsed command line object.
    * @param options Available options for the CLI.
-   * @param entity The entity to apply the command to e.g. metlake, catalog, 
schema, table etc etc.
+   * @param entity The entity to apply the command to e.g. metalake, catalog, 
schema, table etc etc.
    * @param command The type of command to run i.e. list, details, update, 
delete, or create.
    */
   public GravitinoCommandLine(CommandLine line, Options options, String 
entity, String command) {
@@ -204,7 +204,8 @@ public class GravitinoCommandLine {
       String comment = line.getOptionValue(GravitinoOptions.COMMENT);
       new CreateMetalake(url, ignore, metalake, comment).handle();
     } else if (CommandActions.DELETE.equals(command)) {
-      new DeleteMetalake(url, ignore, metalake).handle();
+      boolean force = line.hasOption(GravitinoOptions.FORCE);
+      new DeleteMetalake(url, ignore, force, metalake).handle();
     } else if (CommandActions.SET.equals(command)) {
       String property = line.getOptionValue(GravitinoOptions.PROPERTY);
       String value = line.getOptionValue(GravitinoOptions.VALUE);
@@ -221,7 +222,8 @@ public class GravitinoCommandLine {
       }
       if (line.hasOption(GravitinoOptions.RENAME)) {
         String newName = line.getOptionValue(GravitinoOptions.RENAME);
-        new UpdateMetalakeName(url, ignore, metalake, newName).handle();
+        boolean force = line.hasOption(GravitinoOptions.FORCE);
+        new UpdateMetalakeName(url, ignore, force, metalake, newName).handle();
       }
     }
   }
@@ -254,7 +256,8 @@ public class GravitinoCommandLine {
       Map<String, String> propertyMap = new Properties().parse(properties);
       new CreateCatalog(url, ignore, metalake, catalog, provider, comment, 
propertyMap).handle();
     } else if (CommandActions.DELETE.equals(command)) {
-      new DeleteCatalog(url, ignore, metalake, catalog).handle();
+      boolean force = line.hasOption(GravitinoOptions.FORCE);
+      new DeleteCatalog(url, ignore, force, metalake, catalog).handle();
     } else if (CommandActions.SET.equals(command)) {
       String property = line.getOptionValue(GravitinoOptions.PROPERTY);
       String value = line.getOptionValue(GravitinoOptions.VALUE);
@@ -302,7 +305,8 @@ public class GravitinoCommandLine {
       String comment = line.getOptionValue(GravitinoOptions.COMMENT);
       new CreateSchema(url, ignore, metalake, catalog, schema, 
comment).handle();
     } else if (CommandActions.DELETE.equals(command)) {
-      new DeleteSchema(url, ignore, metalake, catalog, schema).handle();
+      boolean force = line.hasOption(GravitinoOptions.FORCE);
+      new DeleteSchema(url, ignore, force, metalake, catalog, schema).handle();
     } else if (CommandActions.SET.equals(command)) {
       String property = line.getOptionValue(GravitinoOptions.PROPERTY);
       String value = line.getOptionValue(GravitinoOptions.VALUE);
@@ -341,7 +345,8 @@ public class GravitinoCommandLine {
     } else if (CommandActions.CREATE.equals(command)) {
       // TODO
     } else if (CommandActions.DELETE.equals(command)) {
-      new DeleteTable(url, ignore, metalake, catalog, schema, table).handle();
+      boolean force = line.hasOption(GravitinoOptions.FORCE);
+      new DeleteTable(url, ignore, force, metalake, catalog, schema, 
table).handle();
     }
   }
 
@@ -359,7 +364,8 @@ public class GravitinoCommandLine {
     } else if (CommandActions.CREATE.equals(command)) {
       new CreateUser(url, ignore, metalake, user).handle();
     } else if (CommandActions.DELETE.equals(command)) {
-      new DeleteUser(url, ignore, metalake, user).handle();
+      boolean force = line.hasOption(GravitinoOptions.FORCE);
+      new DeleteUser(url, ignore, force, metalake, user).handle();
     }
   }
 
@@ -377,7 +383,8 @@ public class GravitinoCommandLine {
     } else if (CommandActions.CREATE.equals(command)) {
       new CreateGroup(url, ignore, metalake, group).handle();
     } else if (CommandActions.DELETE.equals(command)) {
-      new DeleteGroup(url, ignore, metalake, group).handle();
+      boolean force = line.hasOption(GravitinoOptions.FORCE);
+      new DeleteGroup(url, ignore, force, metalake, group).handle();
     }
   }
 
@@ -400,7 +407,8 @@ public class GravitinoCommandLine {
       String comment = line.getOptionValue(GravitinoOptions.COMMENT);
       new CreateTag(url, ignore, metalake, tag, comment).handle();
     } else if (CommandActions.DELETE.equals(command)) {
-      new DeleteTag(url, ignore, metalake, tag).handle();
+      boolean force = line.hasOption(GravitinoOptions.FORCE);
+      new DeleteTag(url, ignore, force, metalake, tag).handle();
     } else if (CommandActions.SET.equals(command)) {
       String property = line.getOptionValue(GravitinoOptions.PROPERTY);
       String value = line.getOptionValue(GravitinoOptions.VALUE);
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 a9449743c..cb6cfc43d 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
@@ -41,6 +41,7 @@ public class GravitinoOptions {
   public static final String GROUP = "group";
   public static final String TAG = "tag";
   public static final String AUDIT = "audit";
+  public static final String FORCE = "force";
 
   /**
    * Builds and returns the CLI options for Gravitino.
@@ -77,6 +78,9 @@ public class GravitinoOptions {
         Option.builder("p").longOpt(PROPERTIES).desc("property name/value 
pairs").hasArgs().build();
     options.addOption(properties);
 
+    // Force delete entity and rename metalake operations
+    options.addOption(createSimpleOption("f", FORCE, "force operation"));
+
     return options;
   }
 
diff --git 
a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/DeleteCatalog.java
 
b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/DeleteCatalog.java
index 35658e29c..65ebde4e3 100644
--- 
a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/DeleteCatalog.java
+++ 
b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/DeleteCatalog.java
@@ -19,6 +19,7 @@
 
 package org.apache.gravitino.cli.commands;
 
+import org.apache.gravitino.cli.AreYouSure;
 import org.apache.gravitino.cli.ErrorMessages;
 import org.apache.gravitino.client.GravitinoClient;
 import org.apache.gravitino.exceptions.NoSuchCatalogException;
@@ -28,17 +29,21 @@ public class DeleteCatalog extends Command {
 
   protected final String metalake;
   protected final String catalog;
+  protected final boolean force;
 
   /**
    * Delete a catalog.
    *
    * @param url The URL of the Gravitino server.
    * @param ignoreVersions If true don't check the client/server versions 
match.
+   * @param force Force operation.
    * @param metalake The name of the metalake.
    * @param catalog The name of the catalog.
    */
-  public DeleteCatalog(String url, boolean ignoreVersions, String metalake, 
String catalog) {
+  public DeleteCatalog(
+      String url, boolean ignoreVersions, boolean force, String metalake, 
String catalog) {
     super(url, ignoreVersions);
+    this.force = force;
     this.metalake = metalake;
     this.catalog = catalog;
   }
@@ -48,6 +53,10 @@ public class DeleteCatalog extends Command {
   public void handle() {
     boolean deleted = false;
 
+    if (!AreYouSure.really(force)) {
+      return;
+    }
+
     try {
       GravitinoClient client = buildClient(metalake);
       deleted = client.dropCatalog(catalog);
diff --git 
a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/DeleteGroup.java 
b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/DeleteGroup.java
index e13713752..3c3689dc3 100644
--- 
a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/DeleteGroup.java
+++ 
b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/DeleteGroup.java
@@ -19,6 +19,7 @@
 
 package org.apache.gravitino.cli.commands;
 
+import org.apache.gravitino.cli.AreYouSure;
 import org.apache.gravitino.cli.ErrorMessages;
 import org.apache.gravitino.client.GravitinoClient;
 import org.apache.gravitino.exceptions.NoSuchGroupException;
@@ -28,17 +29,21 @@ public class DeleteGroup extends Command {
 
   protected final String metalake;
   protected final String group;
+  protected final boolean force;
 
   /**
    * Delete a group.
    *
    * @param url The URL of the Gravitino server.
    * @param ignoreVersions If true don't check the client/server versions 
match.
+   * @param force Force operation.
    * @param metalake The name of the metalake.
    * @param group The name of the group.
    */
-  public DeleteGroup(String url, boolean ignoreVersions, String metalake, 
String group) {
+  public DeleteGroup(
+      String url, boolean ignoreVersions, boolean force, String metalake, 
String group) {
     super(url, ignoreVersions);
+    this.force = force;
     this.metalake = metalake;
     this.group = group;
   }
@@ -48,6 +53,10 @@ public class DeleteGroup extends Command {
   public void handle() {
     boolean deleted = false;
 
+    if (!AreYouSure.really(force)) {
+      return;
+    }
+
     try {
       GravitinoClient client = buildClient(metalake);
       deleted = client.removeGroup(group);
diff --git 
a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/DeleteMetalake.java
 
b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/DeleteMetalake.java
index 951d8e16b..2162d1818 100644
--- 
a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/DeleteMetalake.java
+++ 
b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/DeleteMetalake.java
@@ -19,22 +19,26 @@
 
 package org.apache.gravitino.cli.commands;
 
+import org.apache.gravitino.cli.AreYouSure;
 import org.apache.gravitino.cli.ErrorMessages;
 import org.apache.gravitino.client.GravitinoAdminClient;
 import org.apache.gravitino.exceptions.NoSuchMetalakeException;
 
 public class DeleteMetalake extends Command {
   protected final String metalake;
+  protected final boolean force;
 
   /**
    * Delete a metalake.
    *
    * @param url The URL of the Gravitino server.
    * @param ignoreVersions If true don't check the client/server versions 
match.
+   * @param force Force operation.
    * @param metalake The name of the metalake.
    */
-  public DeleteMetalake(String url, boolean ignoreVersions, String metalake) {
+  public DeleteMetalake(String url, boolean ignoreVersions, boolean force, 
String metalake) {
     super(url, ignoreVersions);
+    this.force = force;
     this.metalake = metalake;
   }
 
@@ -42,6 +46,11 @@ public class DeleteMetalake extends Command {
   @Override
   public void handle() {
     boolean deleted = false;
+
+    if (!AreYouSure.really(force)) {
+      return;
+    }
+
     try {
       GravitinoAdminClient client = buildAdminClient();
       deleted = client.dropMetalake(metalake);
diff --git 
a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/DeleteSchema.java 
b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/DeleteSchema.java
index f011acbc8..e1676a076 100644
--- 
a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/DeleteSchema.java
+++ 
b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/DeleteSchema.java
@@ -19,6 +19,7 @@
 
 package org.apache.gravitino.cli.commands;
 
+import org.apache.gravitino.cli.AreYouSure;
 import org.apache.gravitino.cli.ErrorMessages;
 import org.apache.gravitino.client.GravitinoClient;
 import org.apache.gravitino.exceptions.NoSuchCatalogException;
@@ -30,19 +31,27 @@ public class DeleteSchema extends Command {
   protected final String metalake;
   protected final String catalog;
   protected final String schema;
+  protected final boolean force;
 
   /**
    * Delete a schema.
    *
    * @param url The URL of the Gravitino server.
    * @param ignoreVersions If true don't check the client/server versions 
match.
+   * @param force Force operation.
    * @param metalake The name of the metalake.
    * @param catalog The name of the catalog.
    * @param schema The name of the schema.
    */
   public DeleteSchema(
-      String url, boolean ignoreVersions, String metalake, String catalog, 
String schema) {
+      String url,
+      boolean ignoreVersions,
+      boolean force,
+      String metalake,
+      String catalog,
+      String schema) {
     super(url, ignoreVersions);
+    this.force = force;
     this.metalake = metalake;
     this.catalog = catalog;
     this.schema = schema;
@@ -53,6 +62,10 @@ public class DeleteSchema extends Command {
   public void handle() {
     boolean deleted = false;
 
+    if (!AreYouSure.really(force)) {
+      return;
+    }
+
     try {
       GravitinoClient client = buildClient(metalake);
       deleted = client.loadCatalog(catalog).asSchemas().dropSchema(schema, 
false);
diff --git 
a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/DeleteTable.java 
b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/DeleteTable.java
index 879dacb3c..ee46d7f38 100644
--- 
a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/DeleteTable.java
+++ 
b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/DeleteTable.java
@@ -20,6 +20,7 @@
 package org.apache.gravitino.cli.commands;
 
 import org.apache.gravitino.NameIdentifier;
+import org.apache.gravitino.cli.AreYouSure;
 import org.apache.gravitino.cli.ErrorMessages;
 import org.apache.gravitino.client.GravitinoClient;
 import org.apache.gravitino.exceptions.NoSuchCatalogException;
@@ -33,12 +34,14 @@ public class DeleteTable extends Command {
   protected final String catalog;
   protected final String schema;
   protected final String table;
+  protected final boolean force;
 
   /**
    * Delete a table.
    *
    * @param url The URL of the Gravitino server.
    * @param ignoreVersions If true don't check the client/server versions 
match.
+   * @param force Force operation.
    * @param metalake The name of the metalake.
    * @param catalog The name of the catalog.
    * @param schema The name of the schema.
@@ -47,11 +50,13 @@ public class DeleteTable extends Command {
   public DeleteTable(
       String url,
       boolean ignoreVersions,
+      boolean force,
       String metalake,
       String catalog,
       String schema,
       String table) {
     super(url, ignoreVersions);
+    this.force = force;
     this.metalake = metalake;
     this.catalog = catalog;
     this.schema = schema;
@@ -63,6 +68,10 @@ public class DeleteTable extends Command {
   public void handle() {
     boolean deleted = false;
 
+    if (!AreYouSure.really(force)) {
+      return;
+    }
+
     try {
       GravitinoClient client = buildClient(metalake);
       NameIdentifier name = NameIdentifier.of(schema, table);
diff --git 
a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/DeleteTag.java 
b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/DeleteTag.java
index 83211eb21..4536897b0 100644
--- a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/DeleteTag.java
+++ b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/DeleteTag.java
@@ -19,6 +19,7 @@
 
 package org.apache.gravitino.cli.commands;
 
+import org.apache.gravitino.cli.AreYouSure;
 import org.apache.gravitino.cli.ErrorMessages;
 import org.apache.gravitino.client.GravitinoClient;
 import org.apache.gravitino.exceptions.NoSuchMetalakeException;
@@ -28,26 +29,33 @@ public class DeleteTag extends Command {
 
   protected final String metalake;
   protected final String tag;
+  protected final boolean force;
 
   /**
    * Delete a tag.
    *
    * @param url The URL of the Gravitino server.
    * @param ignoreVersions If true don't check the client/server versions 
match.
+   * @param force Force operation.
    * @param metalake The name of the metalake.
    * @param tag The name of the tag.
    */
-  public DeleteTag(String url, boolean ignoreVersions, String metalake, String 
tag) {
+  public DeleteTag(String url, boolean ignoreVersions, boolean force, String 
metalake, String tag) {
     super(url, ignoreVersions);
+    this.force = force;
     this.metalake = metalake;
     this.tag = tag;
   }
 
-  /** Delete a catalog. */
+  /** Delete a tag. */
   @Override
   public void handle() {
     boolean deleted = false;
 
+    if (!AreYouSure.really(force)) {
+      return;
+    }
+
     try {
       GravitinoClient client = buildClient(metalake);
       deleted = client.deleteTag(tag);
diff --git 
a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/DeleteUser.java 
b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/DeleteUser.java
index c5ffe69e8..6a748c9bb 100644
--- 
a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/DeleteUser.java
+++ 
b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/DeleteUser.java
@@ -19,6 +19,7 @@
 
 package org.apache.gravitino.cli.commands;
 
+import org.apache.gravitino.cli.AreYouSure;
 import org.apache.gravitino.cli.ErrorMessages;
 import org.apache.gravitino.client.GravitinoClient;
 import org.apache.gravitino.exceptions.NoSuchMetalakeException;
@@ -28,17 +29,21 @@ public class DeleteUser extends Command {
 
   protected final String metalake;
   protected final String user;
+  protected final boolean force;
 
   /**
    * Delete a user.
    *
    * @param url The URL of the Gravitino server.
    * @param ignoreVersions If true don't check the client/server versions 
match.
+   * @param force Force operation.
    * @param metalake The name of the metalake.
    * @param user The name of the user.
    */
-  public DeleteUser(String url, boolean ignoreVersions, String metalake, 
String user) {
+  public DeleteUser(
+      String url, boolean ignoreVersions, boolean force, String metalake, 
String user) {
     super(url, ignoreVersions);
+    this.force = force;
     this.metalake = metalake;
     this.user = user;
   }
@@ -48,6 +53,10 @@ public class DeleteUser extends Command {
   public void handle() {
     boolean deleted = false;
 
+    if (!AreYouSure.really(force)) {
+      return;
+    }
+
     try {
       GravitinoClient client = buildClient(metalake);
       deleted = client.removeUser(user);
diff --git 
a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/UpdateMetalakeName.java
 
b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/UpdateMetalakeName.java
index 48ef26a92..acf5470af 100644
--- 
a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/UpdateMetalakeName.java
+++ 
b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/UpdateMetalakeName.java
@@ -20,6 +20,7 @@
 package org.apache.gravitino.cli.commands;
 
 import org.apache.gravitino.MetalakeChange;
+import org.apache.gravitino.cli.AreYouSure;
 import org.apache.gravitino.cli.ErrorMessages;
 import org.apache.gravitino.client.GravitinoAdminClient;
 import org.apache.gravitino.exceptions.NoSuchMetalakeException;
@@ -29,17 +30,21 @@ public class UpdateMetalakeName extends Command {
 
   protected final String metalake;
   protected final String name;
+  protected final boolean force;
 
   /**
    * Update the name of a metalake.
    *
    * @param url The URL of the Gravitino server.
    * @param ignoreVersions If true don't check the client/server versions 
match.
+   * @param force Force operation.
    * @param metalake The name of the metalake.
    * @param name The new metalake name.
    */
-  public UpdateMetalakeName(String url, boolean ignoreVersions, String 
metalake, String name) {
+  public UpdateMetalakeName(
+      String url, boolean ignoreVersions, boolean force, String metalake, 
String name) {
     super(url, ignoreVersions);
+    this.force = force;
     this.metalake = metalake;
     this.name = name;
   }
@@ -47,6 +52,11 @@ public class UpdateMetalakeName extends Command {
   /** Update the name of a metalake. */
   @Override
   public void handle() {
+
+    if (!AreYouSure.really(force)) {
+      return;
+    }
+
     try {
       GravitinoAdminClient client = buildAdminClient();
       MetalakeChange change = MetalakeChange.rename(name);
diff --git a/docs/cli.md b/docs/cli.md
index 750ab03a2..14b14cf24 100644
--- a/docs/cli.md
+++ b/docs/cli.md
@@ -72,7 +72,7 @@ As dealing with one Metalake is a typical scenario, you can 
set the Metalake nam
 
 The command line option overrides the environment variable and the environment 
variable overrides the configuration file.
 
-## Setting the Gravitino URL
+### Setting the Gravitino URL
 
 As you need to set the Gravitino URL for every command, you can set the URL in 
several ways.
 
@@ -82,7 +82,7 @@ As you need to set the Gravitino URL for every command, you 
can set the URL in s
 
 The command line option overrides the environment variable and the environment 
variable overrides the configuration file.
 
-## Gravitino CLI configuration file
+### Gravitino CLI configuration file
 
 The gravitino CLI can read commonly used CLI options from a configuration 
file. By default, the file is `.gravitino` in the user's home directory. The 
metalake, URL and ignore parameters can be set in this file.
 
@@ -102,7 +102,11 @@ ignore=true
 
 ```
 
-## Manage metadata
+### Potentially unsafe operations
+
+For operations that delete data or rename a metalake the user with be prompted 
to make sure they wish to run this command. The `--force` option can be 
specified to override this behaviour.
+
+### Manage metadata
 
 All the commands are performed by using the [Java API](api/java-api) 
internally.
 
@@ -150,13 +154,17 @@ For commands that accept multiple properties they can be 
specified in a couple o
 
 ### Setting properties and tags
 
-Different options are needed to add a tag and set a property of a tag with 
`gcli tag set`. To add a
-tag, specify the tag (via --tag) and the entity to tag (via --name). To set 
the property of a tag
-(via --tag) you need to specify the property (via --property) and value (via 
--value) you want to
-set.
+ Different options are needed to add a tag and set a property of a tag with 
`gcli tag set`. To add a
+ tag, specify the tag (via --tag) and the entity to tag (via --name). To set 
the property of a tag
+ (via --tag) you need to specify the property (via --property) and value (via 
--value) you want to
+ set.
+
+ To delete a tag, again, you need to specify the tag and entity, to remove a 
tag's property you need
+ to select the tag and property.
+
+### CLI commands
 
-To delete a tag, again, you need to specify the tag and entity, to remove a 
tag's property you need
-to select the tag and property.
+Please set the metalake in the Gravitino configuration file or the environment 
variable before running any of these commands.
 
 ### Metalake commands
 
@@ -169,13 +177,13 @@ gcli metalake list
 #### Show a metalake details
 
 ```bash
-gcli metalake details --metalake metalake_demo
+gcli metalake details
 ```
 
 #### Show a metalake audit information
 
 ```bash
-gcli metalake details --metalake metalake_demo --audit
+gcli metalake details --audit
 ```
 
 #### Create a metalake
@@ -187,37 +195,37 @@ gcli metalake create --metalake my_metalake --comment 
"This is my metalake"
 #### Delete a metalake
 
 ```bash
-gcli metalake delete --metalake my_metalake
+gcli metalake delete
 ```
 
 #### Rename a metalake
 
 ```bash
-gcli metalake update --metalake metalake_demo --rename demo
+gcli metalake update  --rename demo
 ```
 
 #### Update a metalake's comment
 
 ```bash
-gcli metalake update --metalake metalake_demo --comment "new comment"
+gcli metalake update  --comment "new comment"
 ```
 
 #### Display a metalake's properties
 
 ```bash
-gcli metalake properties --metalake metalake_demo
+gcli metalake properties
 ```
 
 #### Set a metalake's property
 
 ```bash
-gcli metalake set --metalake metalake_demo --property test --value value
+gcli metalake set  --property test --value value
 ```
 
 #### Remove a metalake's property
 
 ```bash
-gcli metalake remove --metalake metalake_demo --property test
+gcli metalake remove  --property test
 ```
 
 ### Catalog commands
@@ -225,19 +233,19 @@ gcli metalake remove --metalake metalake_demo --property 
test
 #### Show all catalogs in a metalake
 
 ```bash
-gcli catalog list --metalake metalake_demo
+gcli catalog list
 ```
 
 #### Show a catalog details
 
 ```bash
-gcli catalog details --metalake metalake_demo --name catalog_postgres
+gcli catalog details --name catalog_postgres
 ```
 
 #### Show a catalog audit information
 
 ```bash
-gcli catalog details --metalake metalake_demo --name catalog_postgres --audit
+gcli catalog details --name catalog_postgres --audit
 ```
 
 #### Creating a catalog
@@ -247,67 +255,67 @@ The type of catalog to be created is specified by the 
`--provider` option. Diffe
 ##### Create a Hive catalog
 
 ```bash
-gcli catalog create --metalake metalake_demo --name hive --provider hive 
--properties metastore.uris=thrift://hive-host:9083
+gcli catalog create --name hive --provider hive --properties 
metastore.uris=thrift://hive-host:9083
 ```
 
 ##### Create an Iceberg catalog
 
 ```bash
-gcli catalog create --metalake metalake_demo -name iceberg --provider iceberg 
--properties 
uri=thrift://hive-host:9083,catalog-backend=hive,warehouse=hdfs://hdfs-host:9000/user/iceberg/warehouse
+gcli catalog create  -name iceberg --provider iceberg --properties 
uri=thrift://hive-host:9083,catalog-backend=hive,warehouse=hdfs://hdfs-host:9000/user/iceberg/warehouse
 ```
 
 ##### Create a MySQL catalog
 
 ```bash
-gcli catalog create --metalake metalake_demo -name mysql --provider mysql 
--properties 
jdbc-url=jdbc:mysql://mysql-host:3306?useSSL=false,jdbc-user=user,jdbc-password=password,jdbc-driver=com.mysql.cj.jdbc.Driver
+gcli catalog create  -name mysql --provider mysql --properties 
jdbc-url=jdbc:mysql://mysql-host:3306?useSSL=false,jdbc-user=user,jdbc-password=password,jdbc-driver=com.mysql.cj.jdbc.Driver
 ```
 
 ##### Create a Postgres catalog
 
 ```bash
-gcli catalog create --metalake metalake_demo -name postgres --provider 
postgres --properties 
jdbc-url=jdbc:postgresql://postgresql-host/mydb,jdbc-user=user,jdbc-password=password,jdbc-database=db,jdbc-driver=org.postgresql.Driver
+gcli catalog create  -name postgres --provider postgres --properties 
jdbc-url=jdbc:postgresql://postgresql-host/mydb,jdbc-user=user,jdbc-password=password,jdbc-database=db,jdbc-driver=org.postgresql.Driver
 ```
 
 ##### Create a Kafka catalog
 
 ```bash
-gcli catalog create --metalake metalake_demo -name kafka --provider kafka 
--properties bootstrap.servers=127.0.0.1:9092,127.0.0.2:9092
+gcli catalog create --name kafka --provider kafka --properties 
bootstrap.servers=127.0.0.1:9092,127.0.0.2:9092
 ```
 
 #### Delete a catalog
 
 ```bash
-gcli catalog delete --metalake metalake_demo --name hive
+gcli catalog delete --name hive
 ```
 
 #### Rename a catalog
 
 ```bash
-gcli catalog update --metalake metalake_demo --name catalog_mysql --rename 
mysql
+gcli catalog update --name catalog_mysql --rename mysql
 ```
 
 #### Change a catalog comment
 
 ```bash
-gcli catalog update --metalake metalake_demo --name catalog_mysql --comment 
"new comment"
+gcli catalog update --name catalog_mysql --comment "new comment"
 ```
 
 #### Display a catalog's properties
 
 ```bash
-gcli catalog properties --metalake metalake_demo --name catalog_mysql
+gcli catalog properties --name catalog_mysql
 ```
 
 #### Set a catalog's property
 
 ```bash
-gcli catalog set --metalake metalake_demo --name catalog_mysql --property test 
--value value
+gcli catalog set --name catalog_mysql --property test --value value
 ```
 
 #### Remove a catalog's property
 
 ```bash
-gcli catalog remove --metalake metalake_demo --name catalog_mysql --property 
test
+gcli catalog remove --name catalog_mysql --property test
 ```
 
 ### Schema commands
@@ -315,31 +323,31 @@ gcli catalog remove --metalake metalake_demo --name 
catalog_mysql --property tes
 #### Show all schemas in a catalog
 
 ```bash
-gcli schema list --metalake metalake_demo --name catalog_postgres
+gcli schema list --name catalog_postgres
 ```
 
 #### Show schema details
 
 ```bash
-gcli schema details --metalake metalake_demo --name catalog_postgres.hr
+gcli schema details --name catalog_postgres.hr
 ```
 
 #### Show schema audit information
 
 ```bash
-gcli schema details --metalake metalake_demo --name catalog_postgres.hr --audit
+gcli schema details --name catalog_postgres.hr --audit
 ```
 
 #### Create a schema
 
 ```bash
-gcli schema create --metalake metalake_demo --name catalog_postgres.new_db
+gcli schema create --name catalog_postgres.new_db
 ```
 
 #### Display schema properties
 
 ```bash
-gcli schema properties --metalake metalake_demo --name catalog_postgres.hr -i
+gcli schema properties --name catalog_postgres.hr -i
 ```
 
 Setting and removing schema properties is not currently supported by the Java 
API or the Gravitino CLI.
@@ -349,25 +357,25 @@ Setting and removing schema properties is not currently 
supported by the Java AP
 #### Show all tables
 
 ```bash
-gcli table list --metalake metalake_demo --name catalog_postgres.hr
+gcli table list --name catalog_postgres.hr
 ```
 
 #### Show tables details
 
 ```bash
-gcli column list --metalake metalake_demo --name 
catalog_postgres.hr.departments
+gcli column list --name catalog_postgres.hr.departments
 ```
 
 #### Show tables audit information
 
 ```bash
-gcli table details --metalake metalake_demo --name 
catalog_postgres.hr.departments --audit
+gcli table details --name catalog_postgres.hr.departments --audit
 ```
 
 #### Delete a table
 
 ```bash
-gcli table delete --metalake metalake_demo --name catalog_postgres.hr.salaries
+gcli table delete --name catalog_postgres.hr.salaries
 ```
 
 ### User commands
@@ -375,25 +383,25 @@ gcli table delete --metalake metalake_demo --name 
catalog_postgres.hr.salaries
 #### Create a user
 
 ```bash
-gcli user create --metalake metalake_demo --user new_user
+gcli user create --user new_user
 ```
 
 #### Show a user's details
 
 ```bash
-gcli user details --metalake metalake_demo --user new_user
+gcli user details --user new_user
 ```
 
 #### List all users
 
 ```bash
-gcli user list --metalake metalake_demo
+gcli user list
 ```
 
 #### Delete a user
 
 ```bash
-gcli user delete --metalake metalake_demo --user new_user
+gcli user delete --user new_user
 ```
 
 ### Group commands
@@ -401,97 +409,97 @@ gcli user delete --metalake metalake_demo --user new_user
 #### Create a group
 
 ```bash
-gcli group create --metalake metalake_demo --group new_group
+gcli group create --group new_group
 ```
 
 #### Display a group's details
 
 ```bash
-gcli group details --metalake metalake_demo --group new_group
+gcli group details --group new_group
 ```
 
 #### List all groups
 
 ```bash
-gcli group list --metalake metalake_demo
+gcli group list
 ```
 
 #### Delete a group
 
 ```bash
-gcli group delete --metalake metalake_demo --group new_group
-```
+gcli group delete --group new_group
+ ```
 
 ### Tag commands
 
 #### Display a tag's details
 
 ```bash
-gcli tag details --metalake metalake_demo --tag tagA
+gcli tag details --tag tagA
 ```
 
 #### Create a tag
 
 ```bash
-gcli tag create --metalake metalake_demo --tag tagA
-```
+ gcli tag create --tag tagA
+ ```
 
 #### List all tag
 
 ```bash
-gcli tag list --metalake metalake_demo
+gcli tag list
 ```
 
 #### Delete a tag
 
 ```bash
-gcli tag delete --metalake metalake_demo --tag tagA
+gcli tag delete --tag tagA
 ```
 
 #### Add a tag to an entity
 
 ```bash
-gcli tag set --metalake metalake_demo --name catalog_postgres.hr --tag tagA
+gcli tag set --name catalog_postgres.hr --tag tagA
 ```
 
 #### Remove a tag from an entity
 
 ```bash
-gcli tag remove --metalake metalake_demo --name catalog_postgres.hr --tag tagA
+gcli tag remove --name catalog_postgres.hr --tag tagA
 ```
 
 #### List all tags on an entity
 
 ```bash
-gcli tag list --metalake metalake_demo --name catalog_postgres.hr
+gcli tag list --name catalog_postgres.hr
 ```
 
 #### List the properties of a tag
 
 ```bash
-gcli tag properties --metalake metalake_demo --tag tagA
+gcli tag properties --tag tagA
 ```
 
 #### Set a properties of a tag
 
 ```bash
-gcli tag set --metalake metalake_demo --tag tagA --property test --value value
+gcli tag set --tag tagA --property test --value value
 ```
 
 #### Delete a property of a tag
 
 ```bash
-gcli tag remove --metalake metalake_demo --tag tagA --property test
+gcli tag remove --tag tagA --property test
 ```
 
 #### Rename a tag
 
 ```bash
-gcli tag update --metalake metalake_demo --tag tagA --rename newTag
+gcli tag update --tag tagA --rename newTag
 ```
 
 #### Update a tag's comment
 
 ```bash
-gcli tag update --metalake metalake_demo --tag tagA --comment "new comment"
+gcli tag update --tag tagA --comment "new comment"
 ```


Reply via email to