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 739dcea227 [#6326] Refactor to add a command context to CLI (#6343)
739dcea227 is described below

commit 739dcea2273b5d8230c35d5aac16dd52c4bf120c
Author: Justin Mclean <jus...@classsoftware.com>
AuthorDate: Fri Feb 7 22:45:49 2025 +1100

    [#6326] Refactor to add a command context to CLI (#6343)
    
    ### What changes were proposed in this pull request?
    
    Refactor to add a command context and simple wrappers on output to make
    it easy for "global" command like a "--quiet" option to be added.
    
    Note this in progress as this only has changed Metlake. Some duplicate
    code can be removed once everything is done.
    
    ### Why are the changes needed?
    
    For maintainability.
    
    Fix: #6326
    
    ### Does this PR introduce _any_ user-facing change?
    
    No.
    
    ### How was this patch tested?
    
    Tested locally.
    
    ---------
    
    Co-authored-by: Shaofeng Shi <shaofeng...@gmail.com>
---
 .../org/apache/gravitino/cli/CommandContext.java   | 104 +++++++++++++++++++++
 .../apache/gravitino/cli/GravitinoCommandLine.java |   6 +-
 .../gravitino/cli/MetalakeCommandHandler.java      |  54 ++++-------
 .../apache/gravitino/cli/TestableCommandLine.java  |  50 +++++-----
 .../gravitino/cli/commands/AllMetalakeDetails.java |  10 +-
 .../gravitino/cli/commands/AuditCommand.java       |   8 +-
 .../org/apache/gravitino/cli/commands/Command.java |  35 +++++++
 .../gravitino/cli/commands/CreateMetalake.java     |  10 +-
 .../gravitino/cli/commands/DeleteMetalake.java     |  15 ++-
 .../apache/gravitino/cli/commands/DeleteRole.java  |   4 +-
 .../cli/commands/ListMetalakeProperties.java       |   8 +-
 .../gravitino/cli/commands/ListMetalakes.java      |   9 +-
 .../gravitino/cli/commands/ListProperties.java     |  10 ++
 .../gravitino/cli/commands/MetadataCommand.java    |  10 ++
 .../gravitino/cli/commands/MetalakeAudit.java      |   8 +-
 .../gravitino/cli/commands/MetalakeDetails.java    |   9 +-
 .../gravitino/cli/commands/MetalakeDisable.java    |  10 +-
 .../gravitino/cli/commands/MetalakeEnable.java     |  11 +--
 .../cli/commands/RemoveMetalakeProperty.java       |  11 +--
 .../cli/commands/SetMetalakeProperty.java          |  10 +-
 .../cli/commands/UpdateMetalakeComment.java        |  11 +--
 .../gravitino/cli/commands/UpdateMetalakeName.java |  14 ++-
 .../apache/gravitino/cli/TestMetalakeCommands.java |  70 +++++++-------
 23 files changed, 315 insertions(+), 172 deletions(-)

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
new file mode 100644
index 0000000000..994b97226e
--- /dev/null
+++ b/clients/cli/src/main/java/org/apache/gravitino/cli/CommandContext.java
@@ -0,0 +1,104 @@
+/*
+ * 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 org.apache.gravitino.cli.commands.Command;
+
+/* Context for a command */
+public class CommandContext {
+  private String url;
+  private boolean ignoreVersions;
+  private boolean force;
+  private String outputFormat;
+  // Can add more "global" command flags here without any major changes e.g. a 
guiet flag
+
+  /**
+   * Command constructor.
+   *
+   * @param url The URL of the Gravitino server.
+   * @param ignoreVersions If true don't check the client/server versions 
match.
+   */
+  public CommandContext(String url, boolean ignoreVersions) {
+    this.url = url;
+    this.ignoreVersions = ignoreVersions;
+    this.force = false;
+    this.outputFormat = Command.OUTPUT_FORMAT_PLAIN;
+  }
+
+  /**
+   * Command constructor.
+   *
+   * @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 outputFormat Display output format.
+   */
+  public CommandContext(String url, boolean ignoreVersions, boolean force, 
String outputFormat) {
+    this.url = url;
+    this.ignoreVersions = ignoreVersions;
+    this.force = force;
+    this.outputFormat = outputFormat;
+  }
+
+  /**
+   * Returns the URL.
+   *
+   * @return The URL.
+   */
+  public String url() {
+    return url;
+  }
+
+  /**
+   * Sets the URL.
+   *
+   * @param url The URL to be set.
+   */
+  public void setUrl(String url) {
+    this.url = url;
+  }
+
+  /**
+   * Indicates whether versions should be ignored.
+   *
+   * @return False if versions should be ignored.
+   */
+  public boolean ignoreVersions() {
+    return ignoreVersions;
+  }
+
+  /**
+   * Indicates whether the operation should be forced.
+   *
+   * @return True if the operation should be forced.
+   */
+  public boolean force() {
+    return force;
+  }
+
+  /**
+   * Returns the output format.
+   *
+   * @return The output format.
+   */
+  public String outputFormat() {
+    return outputFormat;
+  }
+}
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 d7e257a8a8..1923562e1f 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
@@ -107,6 +107,10 @@ public class GravitinoCommandLine extends 
TestableCommandLine {
 
   /** Executes the appropriate command based on the command type. */
   private void executeCommand() {
+    boolean force = line.hasOption(GravitinoOptions.FORCE);
+    String outputFormat = line.getOptionValue(GravitinoOptions.OUTPUT);
+    CommandContext context = new CommandContext(null, ignore, force, 
outputFormat);
+
     if (CommandActions.HELP.equals(command)) {
       handleHelpCommand();
     } else if (line.hasOption(GravitinoOptions.OWNER)) {
@@ -120,7 +124,7 @@ public class GravitinoCommandLine extends 
TestableCommandLine {
     } else if (entity.equals(CommandEntities.CATALOG)) {
       new CatalogCommandHandler(this, line, command, ignore).handle();
     } else if (entity.equals(CommandEntities.METALAKE)) {
-      new MetalakeCommandHandler(this, line, command, ignore).handle();
+      new MetalakeCommandHandler(this, line, command, context).handle();
     } else if (entity.equals(CommandEntities.TOPIC)) {
       new TopicCommandHandler(this, line, command, ignore).handle();
     } else if (entity.equals(CommandEntities.FILESET)) {
diff --git 
a/clients/cli/src/main/java/org/apache/gravitino/cli/MetalakeCommandHandler.java
 
b/clients/cli/src/main/java/org/apache/gravitino/cli/MetalakeCommandHandler.java
index 993116f19f..7d39683842 100644
--- 
a/clients/cli/src/main/java/org/apache/gravitino/cli/MetalakeCommandHandler.java
+++ 
b/clients/cli/src/main/java/org/apache/gravitino/cli/MetalakeCommandHandler.java
@@ -29,9 +29,8 @@ public class MetalakeCommandHandler extends CommandHandler {
 
   private final GravitinoCommandLine gravitinoCommandLine;
   private final CommandLine line;
+  private final CommandContext context;
   private final String command;
-  private final boolean ignore;
-  private final String url;
   private String metalake;
 
   /**
@@ -40,15 +39,18 @@ public class MetalakeCommandHandler extends CommandHandler {
    * @param gravitinoCommandLine The Gravitino command line instance.
    * @param line The command line arguments.
    * @param command The command to execute.
-   * @param ignore Ignore server version mismatch.
+   * @param context The command context.
    */
   public MetalakeCommandHandler(
-      GravitinoCommandLine gravitinoCommandLine, CommandLine line, String 
command, boolean ignore) {
+      GravitinoCommandLine gravitinoCommandLine,
+      CommandLine line,
+      String command,
+      CommandContext context) {
     this.gravitinoCommandLine = gravitinoCommandLine;
     this.line = line;
     this.command = command;
-    this.ignore = ignore;
-    this.url = getUrl(line);
+    this.context = context;
+    this.context.setUrl(getUrl(line));
   }
 
   /** Handles the command execution logic based on the provided command. */
@@ -112,33 +114,27 @@ public class MetalakeCommandHandler extends 
CommandHandler {
 
   /** Handles the "LIST" command. */
   private void handleListCommand() {
-    String outputFormat = line.getOptionValue(GravitinoOptions.OUTPUT);
-    gravitinoCommandLine.newListMetalakes(url, ignore, 
outputFormat).validate().handle();
+    gravitinoCommandLine.newListMetalakes(context).validate().handle();
   }
 
   /** Handles the "DETAILS" command. */
   private void handleDetailsCommand() {
     if (line.hasOption(GravitinoOptions.AUDIT)) {
-      gravitinoCommandLine.newMetalakeAudit(url, ignore, 
metalake).validate().handle();
+      gravitinoCommandLine.newMetalakeAudit(context, 
metalake).validate().handle();
     } else {
-      String outputFormat = line.getOptionValue(GravitinoOptions.OUTPUT);
-      gravitinoCommandLine
-          .newMetalakeDetails(url, ignore, outputFormat, metalake)
-          .validate()
-          .handle();
+      gravitinoCommandLine.newMetalakeDetails(context, 
metalake).validate().handle();
     }
   }
 
   /** Handles the "CREATE" command. */
   private void handleCreateCommand() {
     String comment = line.getOptionValue(GravitinoOptions.COMMENT);
-    gravitinoCommandLine.newCreateMetalake(url, ignore, metalake, 
comment).validate().handle();
+    gravitinoCommandLine.newCreateMetalake(context, metalake, 
comment).validate().handle();
   }
 
   /** Handles the "DELETE" command. */
   private void handleDeleteCommand() {
-    boolean force = line.hasOption(GravitinoOptions.FORCE);
-    gravitinoCommandLine.newDeleteMetalake(url, ignore, force, 
metalake).validate().handle();
+    gravitinoCommandLine.newDeleteMetalake(context, 
metalake).validate().handle();
   }
 
   /** Handles the "SET" command. */
@@ -146,7 +142,7 @@ public class MetalakeCommandHandler extends CommandHandler {
     String property = line.getOptionValue(GravitinoOptions.PROPERTY);
     String value = line.getOptionValue(GravitinoOptions.VALUE);
     gravitinoCommandLine
-        .newSetMetalakeProperty(url, ignore, metalake, property, value)
+        .newSetMetalakeProperty(context, metalake, property, value)
         .validate()
         .handle();
   }
@@ -154,15 +150,12 @@ public class MetalakeCommandHandler extends 
CommandHandler {
   /** Handles the "REMOVE" command. */
   private void handleRemoveCommand() {
     String property = line.getOptionValue(GravitinoOptions.PROPERTY);
-    gravitinoCommandLine
-        .newRemoveMetalakeProperty(url, ignore, metalake, property)
-        .validate()
-        .handle();
+    gravitinoCommandLine.newRemoveMetalakeProperty(context, metalake, 
property).validate().handle();
   }
 
   /** Handles the "PROPERTIES" command. */
   private void handlePropertiesCommand() {
-    gravitinoCommandLine.newListMetalakeProperties(url, ignore, 
metalake).validate().handle();
+    gravitinoCommandLine.newListMetalakeProperties(context, 
metalake).validate().handle();
   }
 
   /** Handles the "UPDATE" command. */
@@ -174,28 +167,21 @@ public class MetalakeCommandHandler extends 
CommandHandler {
     if (line.hasOption(GravitinoOptions.ENABLE)) {
       boolean enableAllCatalogs = line.hasOption(GravitinoOptions.ALL);
       gravitinoCommandLine
-          .newMetalakeEnable(url, ignore, metalake, enableAllCatalogs)
+          .newMetalakeEnable(context, metalake, enableAllCatalogs)
           .validate()
           .handle();
     }
     if (line.hasOption(GravitinoOptions.DISABLE)) {
-      gravitinoCommandLine.newMetalakeDisable(url, ignore, 
metalake).validate().handle();
+      gravitinoCommandLine.newMetalakeDisable(context, 
metalake).validate().handle();
     }
 
     if (line.hasOption(GravitinoOptions.COMMENT)) {
       String comment = line.getOptionValue(GravitinoOptions.COMMENT);
-      gravitinoCommandLine
-          .newUpdateMetalakeComment(url, ignore, metalake, comment)
-          .validate()
-          .handle();
+      gravitinoCommandLine.newUpdateMetalakeComment(context, metalake, 
comment).validate().handle();
     }
     if (line.hasOption(GravitinoOptions.RENAME)) {
       String newName = line.getOptionValue(GravitinoOptions.RENAME);
-      boolean force = line.hasOption(GravitinoOptions.FORCE);
-      gravitinoCommandLine
-          .newUpdateMetalakeName(url, ignore, force, metalake, newName)
-          .validate()
-          .handle();
+      gravitinoCommandLine.newUpdateMetalakeName(context, metalake, 
newName).validate().handle();
     }
   }
 }
diff --git 
a/clients/cli/src/main/java/org/apache/gravitino/cli/TestableCommandLine.java 
b/clients/cli/src/main/java/org/apache/gravitino/cli/TestableCommandLine.java
index b229ef16aa..21eec0c865 100644
--- 
a/clients/cli/src/main/java/org/apache/gravitino/cli/TestableCommandLine.java
+++ 
b/clients/cli/src/main/java/org/apache/gravitino/cli/TestableCommandLine.java
@@ -157,52 +157,50 @@ public class TestableCommandLine {
     return new ServerVersion(url, ignore);
   }
 
-  protected MetalakeAudit newMetalakeAudit(String url, boolean ignore, String 
metalake) {
-    return new MetalakeAudit(url, ignore, metalake);
+  protected MetalakeAudit newMetalakeAudit(CommandContext context, String 
metalake) {
+    return new MetalakeAudit(context, metalake);
   }
 
-  protected MetalakeDetails newMetalakeDetails(
-      String url, boolean ignore, String outputFormat, String metalake) {
-    return new MetalakeDetails(url, ignore, outputFormat, metalake);
+  protected MetalakeDetails newMetalakeDetails(CommandContext context, String 
metalake) {
+    return new MetalakeDetails(context, metalake);
   }
 
-  protected ListMetalakes newListMetalakes(String url, boolean ignore, String 
outputFormat) {
-    return new ListMetalakes(url, ignore, outputFormat);
+  protected ListMetalakes newListMetalakes(CommandContext context) {
+    return new ListMetalakes(context);
   }
 
   protected CreateMetalake newCreateMetalake(
-      String url, boolean ignore, String metalake, String comment) {
-    return new CreateMetalake(url, ignore, metalake, comment);
+      CommandContext context, String metalake, String comment) {
+    return new CreateMetalake(context, metalake, comment);
   }
 
-  protected DeleteMetalake newDeleteMetalake(
-      String url, boolean ignore, boolean force, String metalake) {
-    return new DeleteMetalake(url, ignore, force, metalake);
+  protected DeleteMetalake newDeleteMetalake(CommandContext context, String 
metalake) {
+    return new DeleteMetalake(context, metalake);
   }
 
   protected SetMetalakeProperty newSetMetalakeProperty(
-      String url, boolean ignore, String metalake, String property, String 
value) {
-    return new SetMetalakeProperty(url, ignore, metalake, property, value);
+      CommandContext context, String metalake, String property, String value) {
+    return new SetMetalakeProperty(context, metalake, property, value);
   }
 
   protected RemoveMetalakeProperty newRemoveMetalakeProperty(
-      String url, boolean ignore, String metalake, String property) {
-    return new RemoveMetalakeProperty(url, ignore, metalake, property);
+      CommandContext context, String metalake, String property) {
+    return new RemoveMetalakeProperty(context, metalake, property);
   }
 
   protected ListMetalakeProperties newListMetalakeProperties(
-      String url, boolean ignore, String metalake) {
-    return new ListMetalakeProperties(url, ignore, metalake);
+      CommandContext context, String metalake) {
+    return new ListMetalakeProperties(context, metalake);
   }
 
   protected UpdateMetalakeComment newUpdateMetalakeComment(
-      String url, boolean ignore, String metalake, String comment) {
-    return new UpdateMetalakeComment(url, ignore, metalake, comment);
+      CommandContext context, String metalake, String comment) {
+    return new UpdateMetalakeComment(context, metalake, comment);
   }
 
   protected UpdateMetalakeName newUpdateMetalakeName(
-      String url, boolean ignore, boolean force, String metalake, String 
newName) {
-    return new UpdateMetalakeName(url, ignore, force, metalake, newName);
+      CommandContext context, String metalake, String newName) {
+    return new UpdateMetalakeName(context, metalake, newName);
   }
 
   protected CatalogAudit newCatalogAudit(
@@ -908,12 +906,12 @@ public class TestableCommandLine {
   }
 
   protected MetalakeEnable newMetalakeEnable(
-      String url, boolean ignore, String metalake, boolean enableAllCatalogs) {
-    return new MetalakeEnable(url, ignore, metalake, enableAllCatalogs);
+      CommandContext context, String metalake, boolean enableAllCatalogs) {
+    return new MetalakeEnable(context, metalake, enableAllCatalogs);
   }
 
-  protected MetalakeDisable newMetalakeDisable(String url, boolean ignore, 
String metalake) {
-    return new MetalakeDisable(url, ignore, metalake);
+  protected MetalakeDisable newMetalakeDisable(CommandContext context, String 
metalake) {
+    return new MetalakeDisable(context, metalake);
   }
 
   protected CatalogEnable newCatalogEnable(
diff --git 
a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/AllMetalakeDetails.java
 
b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/AllMetalakeDetails.java
index b76138cb5c..cd8deb9c13 100644
--- 
a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/AllMetalakeDetails.java
+++ 
b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/AllMetalakeDetails.java
@@ -23,6 +23,7 @@ import com.google.common.base.Joiner;
 import java.util.ArrayList;
 import java.util.List;
 import org.apache.gravitino.Metalake;
+import org.apache.gravitino.cli.CommandContext;
 import org.apache.gravitino.client.GravitinoAdminClient;
 
 public class AllMetalakeDetails extends Command {
@@ -30,11 +31,10 @@ public class AllMetalakeDetails extends Command {
   /**
    * Parameters needed to list all metalakes.
    *
-   * @param url The URL of the Gravitino server.
-   * @param ignoreVersions If true don't check the client/server versions 
match.
+   * @param context The command context.
    */
-  public AllMetalakeDetails(String url, boolean ignoreVersions) {
-    super(url, ignoreVersions);
+  public AllMetalakeDetails(CommandContext context) {
+    super(context);
   }
 
   /** Displays the name and comment of all metalakes. */
@@ -55,6 +55,6 @@ public class AllMetalakeDetails extends Command {
 
     String all = Joiner.on(System.lineSeparator()).join(metalakeDetails);
 
-    System.out.print(all);
+    printResults(all);
   }
 }
diff --git 
a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/AuditCommand.java 
b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/AuditCommand.java
index 09eee34782..9c27295bdd 100644
--- 
a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/AuditCommand.java
+++ 
b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/AuditCommand.java
@@ -20,6 +20,7 @@
 package org.apache.gravitino.cli.commands;
 
 import org.apache.gravitino.Audit;
+import org.apache.gravitino.cli.CommandContext;
 
 public abstract class AuditCommand extends Command {
   /**
@@ -30,6 +31,11 @@ public abstract class AuditCommand extends Command {
     super(url, ignoreVersions);
   }
 
+  /** @param context The command context. */
+  public AuditCommand(CommandContext context) {
+    super(context);
+  }
+
   /* Overridden in parent - do nothing  */
   @Override
   public void handle() {}
@@ -51,6 +57,6 @@ public abstract class AuditCommand extends Command {
             + ","
             + audit.lastModifiedTime();
 
-    System.out.println(auditInfo);
+    printResults(auditInfo);
   }
 }
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 ea6abdd639..7d259ed18b 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
@@ -23,6 +23,7 @@ import static 
org.apache.gravitino.client.GravitinoClientBase.Builder;
 
 import com.google.common.base.Joiner;
 import java.io.File;
+import org.apache.gravitino.cli.CommandContext;
 import org.apache.gravitino.cli.ErrorMessages;
 import org.apache.gravitino.cli.GravitinoConfig;
 import org.apache.gravitino.cli.KerberosData;
@@ -49,10 +50,25 @@ public abstract class Command {
   private static final String SIMPLE_AUTH = "simple";
   private static final String OAUTH_AUTH = "oauth";
   private static final String KERBEROS_AUTH = "kerberos";
+
   private final String url;
   private final boolean ignoreVersions;
   private final String outputFormat;
 
+  protected CommandContext context = null; // TODO make final
+
+  /**
+   * Command constructor.
+   *
+   * @param context The command context.
+   */
+  public Command(CommandContext context) {
+    this.context = context;
+    this.url = context.url();
+    this.ignoreVersions = context.ignoreVersions();
+    this.outputFormat = context.outputFormat();
+  }
+
   /**
    * Command constructor.
    *
@@ -88,6 +104,25 @@ public abstract class Command {
     Main.exit(-1);
   }
 
+  /**
+   * Prints out an informational message, often to indicate a command has 
finished.
+   *
+   * @param message The message to display.
+   */
+  public void printInformation(String message) {
+    // so that future outoput could be suppressed
+    System.out.print(message);
+  }
+
+  /**
+   * Prints out an a results of a command.
+   *
+   * @param results The results to display.
+   */
+  public void printResults(String results) {
+    System.out.print(results);
+  }
+
   /**
    * Sets the authentication mode and user credentials for the command.
    *
diff --git 
a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/CreateMetalake.java
 
b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/CreateMetalake.java
index 9a3c033f02..cdb9472f20 100644
--- 
a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/CreateMetalake.java
+++ 
b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/CreateMetalake.java
@@ -19,6 +19,7 @@
 
 package org.apache.gravitino.cli.commands;
 
+import org.apache.gravitino.cli.CommandContext;
 import org.apache.gravitino.cli.ErrorMessages;
 import org.apache.gravitino.client.GravitinoAdminClient;
 import org.apache.gravitino.exceptions.MetalakeAlreadyExistsException;
@@ -30,13 +31,12 @@ public class CreateMetalake extends Command {
   /**
    * Create a new metalake.
    *
-   * @param url The URL of the Gravitino server.
-   * @param ignoreVersions If true don't check the client/server versions 
match.
+   * @param context The command context.
    * @param metalake The name of the metalake.
    * @param comment The metalake's comment.
    */
-  public CreateMetalake(String url, boolean ignoreVersions, String metalake, 
String comment) {
-    super(url, ignoreVersions);
+  public CreateMetalake(CommandContext context, String metalake, String 
comment) {
+    super(context);
     this.metalake = metalake;
     this.comment = comment;
   }
@@ -53,6 +53,6 @@ public class CreateMetalake extends Command {
       exitWithError(exp.getMessage());
     }
 
-    System.out.println(metalake + " created");
+    printInformation(metalake + " created");
   }
 }
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 3bad108a9e..4f72058cd1 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
@@ -20,6 +20,7 @@
 package org.apache.gravitino.cli.commands;
 
 import org.apache.gravitino.cli.AreYouSure;
+import org.apache.gravitino.cli.CommandContext;
 import org.apache.gravitino.cli.ErrorMessages;
 import org.apache.gravitino.client.GravitinoAdminClient;
 import org.apache.gravitino.exceptions.MetalakeInUseException;
@@ -32,14 +33,12 @@ public class DeleteMetalake extends Command {
   /**
    * 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 context The command context.
    * @param metalake The name of the metalake.
    */
-  public DeleteMetalake(String url, boolean ignoreVersions, boolean force, 
String metalake) {
-    super(url, ignoreVersions);
-    this.force = force;
+  public DeleteMetalake(CommandContext context, String metalake) {
+    super(context);
+    this.force = context.force();
     this.metalake = metalake;
   }
 
@@ -64,9 +63,9 @@ public class DeleteMetalake extends Command {
     }
 
     if (deleted) {
-      System.out.println(metalake + " deleted.");
+      printInformation(metalake + " deleted.");
     } else {
-      System.out.println(metalake + " not deleted.");
+      printInformation(metalake + " not deleted.");
     }
   }
 }
diff --git 
a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/DeleteRole.java 
b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/DeleteRole.java
index fa7c8cacc2..4e0bb508d1 100644
--- 
a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/DeleteRole.java
+++ 
b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/DeleteRole.java
@@ -74,9 +74,9 @@ public class DeleteRole extends Command {
     }
 
     if (failedRoles.isEmpty()) {
-      System.out.println(COMMA_JOINER.join(successRoles) + " deleted.");
+      printInformation(COMMA_JOINER.join(successRoles) + " deleted.");
     } else {
-      System.err.println(
+      printInformation(
           COMMA_JOINER.join(successRoles)
               + " deleted, "
               + "but "
diff --git 
a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListMetalakeProperties.java
 
b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListMetalakeProperties.java
index b7d794d445..2e85058d12 100644
--- 
a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListMetalakeProperties.java
+++ 
b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListMetalakeProperties.java
@@ -21,6 +21,7 @@ package org.apache.gravitino.cli.commands;
 
 import java.util.Map;
 import org.apache.gravitino.Metalake;
+import org.apache.gravitino.cli.CommandContext;
 import org.apache.gravitino.cli.ErrorMessages;
 import org.apache.gravitino.client.GravitinoAdminClient;
 import org.apache.gravitino.exceptions.NoSuchMetalakeException;
@@ -33,12 +34,11 @@ public class ListMetalakeProperties extends ListProperties {
   /**
    * List the properties of a metalake.
    *
-   * @param url The URL of the Gravitino server.
-   * @param ignoreVersions If true don't check the client/server versions 
match.
+   * @param context The command context.
    * @param metalake The name of the metalake.
    */
-  public ListMetalakeProperties(String url, boolean ignoreVersions, String 
metalake) {
-    super(url, ignoreVersions);
+  public ListMetalakeProperties(CommandContext context, String metalake) {
+    super(context);
     this.metalake = metalake;
   }
 
diff --git 
a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListMetalakes.java
 
b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListMetalakes.java
index ee5ac81d64..a97e89bca2 100644
--- 
a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListMetalakes.java
+++ 
b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListMetalakes.java
@@ -20,6 +20,7 @@
 package org.apache.gravitino.cli.commands;
 
 import org.apache.gravitino.Metalake;
+import org.apache.gravitino.cli.CommandContext;
 import org.apache.gravitino.client.GravitinoAdminClient;
 
 /** Lists all metalakes. */
@@ -28,12 +29,10 @@ public class ListMetalakes extends Command {
   /**
    * List all metalakes.
    *
-   * @param url The URL of the Gravitino server.
-   * @param ignoreVersions If true don't check the client/server versions 
match.
-   * @param outputFormat The output format.
+   * @param context The command context.
    */
-  public ListMetalakes(String url, boolean ignoreVersions, String 
outputFormat) {
-    super(url, ignoreVersions, outputFormat);
+  public ListMetalakes(CommandContext context) {
+    super(context);
   }
 
   /** Lists all metalakes. */
diff --git 
a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListProperties.java
 
b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListProperties.java
index a7d08ba36e..55c750aa71 100644
--- 
a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListProperties.java
+++ 
b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/ListProperties.java
@@ -20,10 +20,20 @@
 package org.apache.gravitino.cli.commands;
 
 import java.util.Map;
+import org.apache.gravitino.cli.CommandContext;
 
 /** List the properties of a metalake. */
 public class ListProperties extends Command {
 
+  /**
+   * List the properties of an entity.
+   *
+   * @param context The command context.
+   */
+  public ListProperties(CommandContext context) {
+    super(context);
+  }
+
   /**
    * List the properties of an entity.
    *
diff --git 
a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/MetadataCommand.java
 
b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/MetadataCommand.java
index 3f1e347c1f..0ff7bce294 100644
--- 
a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/MetadataCommand.java
+++ 
b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/MetadataCommand.java
@@ -22,6 +22,7 @@ package org.apache.gravitino.cli.commands;
 import org.apache.gravitino.Catalog;
 import org.apache.gravitino.MetadataObject;
 import org.apache.gravitino.MetadataObjects;
+import org.apache.gravitino.cli.CommandContext;
 import org.apache.gravitino.cli.FullName;
 import org.apache.gravitino.client.GravitinoClient;
 
@@ -37,6 +38,15 @@ public class MetadataCommand extends Command {
     super(url, ignoreVersions);
   }
 
+  /**
+   * MetadataCommand constructor.
+   *
+   * @param context The command context.
+   */
+  public MetadataCommand(CommandContext context) {
+    super(context);
+  }
+
   /**
    * Constructs a {@link MetadataObject} based on the provided client, 
existing metadata object, and
    * entity name.
diff --git 
a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/MetalakeAudit.java
 
b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/MetalakeAudit.java
index b966a1ae29..76d953e5b8 100644
--- 
a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/MetalakeAudit.java
+++ 
b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/MetalakeAudit.java
@@ -20,6 +20,7 @@
 package org.apache.gravitino.cli.commands;
 
 import org.apache.gravitino.Audit;
+import org.apache.gravitino.cli.CommandContext;
 import org.apache.gravitino.cli.ErrorMessages;
 import org.apache.gravitino.client.GravitinoClient;
 import org.apache.gravitino.exceptions.NoSuchMetalakeException;
@@ -31,12 +32,11 @@ public class MetalakeAudit extends AuditCommand {
   /**
    * Displays metalake audit information.
    *
-   * @param url The URL of the Gravitino server.
-   * @param ignoreVersions If true don't check the client/server versions 
match.
+   * @param context The command context.
    * @param metalake The name of the metalake.
    */
-  public MetalakeAudit(String url, boolean ignoreVersions, String metalake) {
-    super(url, ignoreVersions);
+  public MetalakeAudit(CommandContext context, String metalake) {
+    super(context);
     this.metalake = metalake;
   }
 
diff --git 
a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/MetalakeDetails.java
 
b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/MetalakeDetails.java
index ea503710d4..cc2bf6ce4b 100644
--- 
a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/MetalakeDetails.java
+++ 
b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/MetalakeDetails.java
@@ -20,6 +20,7 @@
 package org.apache.gravitino.cli.commands;
 
 import org.apache.gravitino.Metalake;
+import org.apache.gravitino.cli.CommandContext;
 import org.apache.gravitino.cli.ErrorMessages;
 import org.apache.gravitino.client.GravitinoClient;
 import org.apache.gravitino.exceptions.NoSuchMetalakeException;
@@ -31,13 +32,11 @@ public class MetalakeDetails extends Command {
   /**
    * Displays metalake details.
    *
-   * @param url The URL of the Gravitino server.
-   * @param ignoreVersions If true don't check the client/server versions 
match.
-   * @param outputFormat The output format.
+   * @param context The command context.
    * @param metalake The name of the metalake.
    */
-  public MetalakeDetails(String url, boolean ignoreVersions, String 
outputFormat, String metalake) {
-    super(url, ignoreVersions, outputFormat);
+  public MetalakeDetails(CommandContext context, String metalake) {
+    super(context);
     this.metalake = metalake;
   }
 
diff --git 
a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/MetalakeDisable.java
 
b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/MetalakeDisable.java
index 02e33a45d4..ad05d29343 100644
--- 
a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/MetalakeDisable.java
+++ 
b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/MetalakeDisable.java
@@ -19,6 +19,7 @@
 
 package org.apache.gravitino.cli.commands;
 
+import org.apache.gravitino.cli.CommandContext;
 import org.apache.gravitino.cli.ErrorMessages;
 import org.apache.gravitino.client.GravitinoAdminClient;
 import org.apache.gravitino.exceptions.NoSuchMetalakeException;
@@ -30,12 +31,11 @@ public class MetalakeDisable extends Command {
   /**
    * Disable metalake
    *
-   * @param url The URL of the Gravitino server.
-   * @param ignoreVersions If true don't check the client/server versions 
match.
+   * @param context The command context.
    * @param metalake The name of the metalake.
    */
-  public MetalakeDisable(String url, boolean ignoreVersions, String metalake) {
-    super(url, ignoreVersions);
+  public MetalakeDisable(CommandContext context, String metalake) {
+    super(context);
     this.metalake = metalake;
   }
 
@@ -51,6 +51,6 @@ public class MetalakeDisable extends Command {
       exitWithError(exp.getMessage());
     }
 
-    System.out.println(metalake + " has been disabled.");
+    printInformation(metalake + " has been disabled.");
   }
 }
diff --git 
a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/MetalakeEnable.java
 
b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/MetalakeEnable.java
index 34ba23a61b..f402c37608 100644
--- 
a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/MetalakeEnable.java
+++ 
b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/MetalakeEnable.java
@@ -20,6 +20,7 @@
 package org.apache.gravitino.cli.commands;
 
 import java.util.Arrays;
+import org.apache.gravitino.cli.CommandContext;
 import org.apache.gravitino.cli.ErrorMessages;
 import org.apache.gravitino.client.GravitinoAdminClient;
 import org.apache.gravitino.client.GravitinoMetalake;
@@ -34,14 +35,12 @@ public class MetalakeEnable extends Command {
   /**
    * Enable a metalake
    *
-   * @param url The URL of the Gravitino server.
-   * @param ignoreVersions If true don't check the client/server versions 
match.
+   * @param context The command context.
    * @param metalake The name of the metalake.
    * @param enableAllCatalogs Whether to enable all catalogs.
    */
-  public MetalakeEnable(
-      String url, boolean ignoreVersions, String metalake, boolean 
enableAllCatalogs) {
-    super(url, ignoreVersions);
+  public MetalakeEnable(CommandContext context, String metalake, boolean 
enableAllCatalogs) {
+    super(context);
     this.metalake = metalake;
     this.enableAllCatalogs = enableAllCatalogs;
   }
@@ -67,6 +66,6 @@ public class MetalakeEnable extends Command {
       exitWithError(exp.getMessage());
     }
 
-    System.out.println(msgBuilder);
+    printInformation(msgBuilder.toString());
   }
 }
diff --git 
a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/RemoveMetalakeProperty.java
 
b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/RemoveMetalakeProperty.java
index ce3a50fee1..ad00aa2fd2 100644
--- 
a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/RemoveMetalakeProperty.java
+++ 
b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/RemoveMetalakeProperty.java
@@ -20,6 +20,7 @@
 package org.apache.gravitino.cli.commands;
 
 import org.apache.gravitino.MetalakeChange;
+import org.apache.gravitino.cli.CommandContext;
 import org.apache.gravitino.cli.ErrorMessages;
 import org.apache.gravitino.client.GravitinoAdminClient;
 import org.apache.gravitino.exceptions.NoSuchMetalakeException;
@@ -33,14 +34,12 @@ public class RemoveMetalakeProperty extends Command {
   /**
    * Remove a property of a metalake.
    *
-   * @param url The URL of the Gravitino server.
-   * @param ignoreVersions If true don't check the client/server versions 
match.
+   * @param context The command context.
    * @param metalake The name of the metalake.
    * @param property The name of the property.
    */
-  public RemoveMetalakeProperty(
-      String url, boolean ignoreVersions, String metalake, String property) {
-    super(url, ignoreVersions);
+  public RemoveMetalakeProperty(CommandContext context, String metalake, 
String property) {
+    super(context);
     this.metalake = metalake;
     this.property = property;
   }
@@ -58,7 +57,7 @@ public class RemoveMetalakeProperty extends Command {
       exitWithError(exp.getMessage());
     }
 
-    System.out.println(property + " property removed.");
+    printInformation(property + " property removed.");
   }
 
   @Override
diff --git 
a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/SetMetalakeProperty.java
 
b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/SetMetalakeProperty.java
index ef67d008bc..330ebb6398 100644
--- 
a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/SetMetalakeProperty.java
+++ 
b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/SetMetalakeProperty.java
@@ -20,6 +20,7 @@
 package org.apache.gravitino.cli.commands;
 
 import org.apache.gravitino.MetalakeChange;
+import org.apache.gravitino.cli.CommandContext;
 import org.apache.gravitino.cli.ErrorMessages;
 import org.apache.gravitino.client.GravitinoAdminClient;
 import org.apache.gravitino.exceptions.NoSuchMetalakeException;
@@ -34,15 +35,14 @@ public class SetMetalakeProperty extends Command {
   /**
    * Set a property of a metalake.
    *
-   * @param url The URL of the Gravitino server.
-   * @param ignoreVersions If true don't check the client/server versions 
match.
+   * @param context The command context.
    * @param metalake The name of the metalake.
    * @param property The name of the property.
    * @param value The value of the property.
    */
   public SetMetalakeProperty(
-      String url, boolean ignoreVersions, String metalake, String property, 
String value) {
-    super(url, ignoreVersions);
+      CommandContext context, String metalake, String property, String value) {
+    super(context);
     this.metalake = metalake;
     this.property = property;
     this.value = value;
@@ -61,7 +61,7 @@ public class SetMetalakeProperty extends Command {
       exitWithError(exp.getMessage());
     }
 
-    System.out.println(metalake + " property set.");
+    printInformation(metalake + " property set.");
   }
 
   @Override
diff --git 
a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/UpdateMetalakeComment.java
 
b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/UpdateMetalakeComment.java
index 9ca63084e7..96a5a92741 100644
--- 
a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/UpdateMetalakeComment.java
+++ 
b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/UpdateMetalakeComment.java
@@ -20,6 +20,7 @@
 package org.apache.gravitino.cli.commands;
 
 import org.apache.gravitino.MetalakeChange;
+import org.apache.gravitino.cli.CommandContext;
 import org.apache.gravitino.cli.ErrorMessages;
 import org.apache.gravitino.client.GravitinoAdminClient;
 import org.apache.gravitino.exceptions.NoSuchMetalakeException;
@@ -33,14 +34,12 @@ public class UpdateMetalakeComment extends Command {
   /**
    * Update the comment of a metalake.
    *
-   * @param url The URL of the Gravitino server.
-   * @param ignoreVersions If true don't check the client/server versions 
match.
+   * @param context The command context.
    * @param metalake The name of the metalake.
    * @param comment New metalake comment.
    */
-  public UpdateMetalakeComment(
-      String url, boolean ignoreVersions, String metalake, String comment) {
-    super(url, ignoreVersions);
+  public UpdateMetalakeComment(CommandContext context, String metalake, String 
comment) {
+    super(context);
     this.metalake = metalake;
     this.comment = comment;
   }
@@ -58,6 +57,6 @@ public class UpdateMetalakeComment extends Command {
       exitWithError(exp.getMessage());
     }
 
-    System.out.println(metalake + " comment changed.");
+    printInformation(metalake + " comment changed.");
   }
 }
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 275ba3165d..60497d034d 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
@@ -21,6 +21,7 @@ package org.apache.gravitino.cli.commands;
 
 import org.apache.gravitino.MetalakeChange;
 import org.apache.gravitino.cli.AreYouSure;
+import org.apache.gravitino.cli.CommandContext;
 import org.apache.gravitino.cli.ErrorMessages;
 import org.apache.gravitino.client.GravitinoAdminClient;
 import org.apache.gravitino.exceptions.NoSuchMetalakeException;
@@ -35,16 +36,13 @@ public class UpdateMetalakeName extends Command {
   /**
    * 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 context The command context.
    * @param metalake The name of the metalake.
    * @param name The new metalake name.
    */
-  public UpdateMetalakeName(
-      String url, boolean ignoreVersions, boolean force, String metalake, 
String name) {
-    super(url, ignoreVersions);
-    this.force = force;
+  public UpdateMetalakeName(CommandContext context, String metalake, String 
name) {
+    super(context);
+    this.force = context.force();
     this.metalake = metalake;
     this.name = name;
   }
@@ -67,6 +65,6 @@ public class UpdateMetalakeName extends Command {
       exitWithError(exp.getMessage());
     }
 
-    System.out.println(metalake + " name changed.");
+    printInformation(metalake + " name changed.");
   }
 }
diff --git 
a/clients/cli/src/test/java/org/apache/gravitino/cli/TestMetalakeCommands.java 
b/clients/cli/src/test/java/org/apache/gravitino/cli/TestMetalakeCommands.java
index dae2fe6340..37e3acd289 100644
--- 
a/clients/cli/src/test/java/org/apache/gravitino/cli/TestMetalakeCommands.java
+++ 
b/clients/cli/src/test/java/org/apache/gravitino/cli/TestMetalakeCommands.java
@@ -22,7 +22,10 @@ package org.apache.gravitino.cli;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertThrows;
 import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.any;
 import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.eq;
+import static org.mockito.Mockito.isNull;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.never;
 import static org.mockito.Mockito.spy;
@@ -65,6 +68,7 @@ class TestMetalakeCommands {
     mockOptions = mock(Options.class);
     System.setOut(new PrintStream(outContent));
     System.setErr(new PrintStream(errContent));
+    Main.useExit = false;
   }
 
   @AfterEach
@@ -87,9 +91,7 @@ class TestMetalakeCommands {
         spy(
             new GravitinoCommandLine(
                 mockCommandLine, mockOptions, CommandEntities.METALAKE, 
CommandActions.LIST));
-    doReturn(mockList)
-        .when(commandLine)
-        .newListMetalakes(GravitinoCommandLine.DEFAULT_URL, false, null);
+    
doReturn(mockList).when(commandLine).newListMetalakes(any(CommandContext.class));
     doReturn(mockList).when(mockList).validate();
     commandLine.handleCommandLine();
     verify(mockList).handle();
@@ -107,7 +109,7 @@ class TestMetalakeCommands {
                 mockCommandLine, mockOptions, CommandEntities.METALAKE, 
CommandActions.DETAILS));
     doReturn(mockDetails)
         .when(commandLine)
-        .newMetalakeDetails(GravitinoCommandLine.DEFAULT_URL, false, null, 
"metalake_demo");
+        .newMetalakeDetails(any(CommandContext.class), eq("metalake_demo"));
     doReturn(mockDetails).when(mockDetails).validate();
     commandLine.handleCommandLine();
     verify(mockDetails).handle();
@@ -125,7 +127,7 @@ class TestMetalakeCommands {
                 mockCommandLine, mockOptions, CommandEntities.METALAKE, 
CommandActions.DETAILS));
     doReturn(mockAudit)
         .when(commandLine)
-        .newMetalakeAudit(GravitinoCommandLine.DEFAULT_URL, false, 
"metalake_demo");
+        .newMetalakeAudit(any(CommandContext.class), eq("metalake_demo"));
     doReturn(mockAudit).when(mockAudit).validate();
     commandLine.handleCommandLine();
     verify(mockAudit).handle();
@@ -144,7 +146,7 @@ class TestMetalakeCommands {
                 mockCommandLine, mockOptions, CommandEntities.METALAKE, 
CommandActions.CREATE));
     doReturn(mockCreate)
         .when(commandLine)
-        .newCreateMetalake(GravitinoCommandLine.DEFAULT_URL, false, 
"metalake_demo", "comment");
+        .newCreateMetalake(any(CommandContext.class), eq("metalake_demo"), 
eq("comment"));
     doReturn(mockCreate).when(mockCreate).validate();
     commandLine.handleCommandLine();
     verify(mockCreate).handle();
@@ -161,7 +163,7 @@ class TestMetalakeCommands {
                 mockCommandLine, mockOptions, CommandEntities.METALAKE, 
CommandActions.CREATE));
     doReturn(mockCreate)
         .when(commandLine)
-        .newCreateMetalake(GravitinoCommandLine.DEFAULT_URL, false, 
"metalake_demo", null);
+        .newCreateMetalake(any(CommandContext.class), eq("metalake_demo"), 
isNull());
     doReturn(mockCreate).when(mockCreate).validate();
     commandLine.handleCommandLine();
     verify(mockCreate).handle();
@@ -178,7 +180,7 @@ class TestMetalakeCommands {
                 mockCommandLine, mockOptions, CommandEntities.METALAKE, 
CommandActions.DELETE));
     doReturn(mockDelete)
         .when(commandLine)
-        .newDeleteMetalake(GravitinoCommandLine.DEFAULT_URL, false, false, 
"metalake_demo");
+        .newDeleteMetalake(any(CommandContext.class), eq("metalake_demo"));
     doReturn(mockDelete).when(mockDelete).validate();
     commandLine.handleCommandLine();
     verify(mockDelete).handle();
@@ -189,14 +191,13 @@ class TestMetalakeCommands {
     DeleteMetalake mockDelete = mock(DeleteMetalake.class);
     
when(mockCommandLine.hasOption(GravitinoOptions.METALAKE)).thenReturn(true);
     
when(mockCommandLine.getOptionValue(GravitinoOptions.METALAKE)).thenReturn("metalake_demo");
-    when(mockCommandLine.hasOption(GravitinoOptions.FORCE)).thenReturn(true);
     GravitinoCommandLine commandLine =
         spy(
             new GravitinoCommandLine(
                 mockCommandLine, mockOptions, CommandEntities.METALAKE, 
CommandActions.DELETE));
     doReturn(mockDelete)
         .when(commandLine)
-        .newDeleteMetalake(GravitinoCommandLine.DEFAULT_URL, false, true, 
"metalake_demo");
+        .newDeleteMetalake(any(CommandContext.class), eq("metalake_demo"));
     doReturn(mockDelete).when(mockDelete).validate();
     commandLine.handleCommandLine();
     verify(mockDelete).handle();
@@ -218,7 +219,7 @@ class TestMetalakeCommands {
     doReturn(mockSetProperty)
         .when(commandLine)
         .newSetMetalakeProperty(
-            GravitinoCommandLine.DEFAULT_URL, false, "metalake_demo", 
"property", "value");
+            any(CommandContext.class), eq("metalake_demo"), eq("property"), 
eq("value"));
     doReturn(mockSetProperty).when(mockSetProperty).validate();
     commandLine.handleCommandLine();
     verify(mockSetProperty).handle();
@@ -226,11 +227,11 @@ class TestMetalakeCommands {
 
   @Test
   void testSetMetalakePropertyCommandWithoutPropertyAndValue() {
+    CommandContext context = new 
CommandContext(GravitinoCommandLine.DEFAULT_URL, false);
+
     Main.useExit = false;
     SetMetalakeProperty metalakeProperty =
-        spy(
-            new SetMetalakeProperty(
-                GravitinoCommandLine.DEFAULT_URL, false, "demo_metalake", 
null, null));
+        spy(new SetMetalakeProperty(context, "demo_metalake", null, null));
 
     assertThrows(RuntimeException.class, metalakeProperty::validate);
     String errOutput = new String(errContent.toByteArray(), 
StandardCharsets.UTF_8).trim();
@@ -239,11 +240,11 @@ class TestMetalakeCommands {
 
   @Test
   void testSetMetalakePropertyCommandWithoutProperty() {
+    CommandContext context = new 
CommandContext(GravitinoCommandLine.DEFAULT_URL, false);
+
     Main.useExit = false;
     SetMetalakeProperty metalakeProperty =
-        spy(
-            new SetMetalakeProperty(
-                GravitinoCommandLine.DEFAULT_URL, false, "demo_metalake", 
null, "val1"));
+        spy(new SetMetalakeProperty(context, "demo_metalake", null, "val1"));
 
     assertThrows(RuntimeException.class, metalakeProperty::validate);
     String errOutput = new String(errContent.toByteArray(), 
StandardCharsets.UTF_8).trim();
@@ -252,11 +253,11 @@ class TestMetalakeCommands {
 
   @Test
   void testSetMetalakePropertyCommandWithoutValue() {
+    CommandContext context = new 
CommandContext(GravitinoCommandLine.DEFAULT_URL, false);
+
     Main.useExit = false;
     SetMetalakeProperty metalakeProperty =
-        spy(
-            new SetMetalakeProperty(
-                GravitinoCommandLine.DEFAULT_URL, false, "demo_metalake", 
"property1", null));
+        spy(new SetMetalakeProperty(context, "demo_metalake", "property1", 
null));
 
     assertThrows(RuntimeException.class, metalakeProperty::validate);
     String errOutput = new String(errContent.toByteArray(), 
StandardCharsets.UTF_8).trim();
@@ -276,8 +277,7 @@ class TestMetalakeCommands {
                 mockCommandLine, mockOptions, CommandEntities.METALAKE, 
CommandActions.REMOVE));
     doReturn(mockRemoveProperty)
         .when(commandLine)
-        .newRemoveMetalakeProperty(
-            GravitinoCommandLine.DEFAULT_URL, false, "metalake_demo", 
"property");
+        .newRemoveMetalakeProperty(any(CommandContext.class), 
eq("metalake_demo"), eq("property"));
     doReturn(mockRemoveProperty).when(mockRemoveProperty).validate();
     commandLine.handleCommandLine();
     verify(mockRemoveProperty).handle();
@@ -285,11 +285,11 @@ class TestMetalakeCommands {
 
   @Test
   void testRemoveMetalakePropertyCommandWithoutProperty() {
+    CommandContext context = new 
CommandContext(GravitinoCommandLine.DEFAULT_URL, false);
+
     Main.useExit = false;
     RemoveMetalakeProperty mockRemoveProperty =
-        spy(
-            new RemoveMetalakeProperty(
-                GravitinoCommandLine.DEFAULT_URL, false, "demo_metalake", 
null));
+        spy(new RemoveMetalakeProperty(context, "demo_metalake", null));
 
     assertThrows(RuntimeException.class, mockRemoveProperty::validate);
     String errOutput = new String(errContent.toByteArray(), 
StandardCharsets.UTF_8).trim();
@@ -307,7 +307,7 @@ class TestMetalakeCommands {
                 mockCommandLine, mockOptions, CommandEntities.METALAKE, 
CommandActions.PROPERTIES));
     doReturn(mockListProperties)
         .when(commandLine)
-        .newListMetalakeProperties(GravitinoCommandLine.DEFAULT_URL, false, 
"metalake_demo");
+        .newListMetalakeProperties(any(CommandContext.class), 
eq("metalake_demo"));
     doReturn(mockListProperties).when(mockListProperties).validate();
     commandLine.handleCommandLine();
     verify(mockListProperties).handle();
@@ -327,7 +327,7 @@ class TestMetalakeCommands {
     doReturn(mockUpdateComment)
         .when(commandLine)
         .newUpdateMetalakeComment(
-            GravitinoCommandLine.DEFAULT_URL, false, "metalake_demo", "new 
comment");
+            any(CommandContext.class), eq("metalake_demo"), eq("new comment"));
     doReturn(mockUpdateComment).when(mockUpdateComment).validate();
     commandLine.handleCommandLine();
     verify(mockUpdateComment).handle();
@@ -346,8 +346,7 @@ class TestMetalakeCommands {
                 mockCommandLine, mockOptions, CommandEntities.METALAKE, 
CommandActions.UPDATE));
     doReturn(mockUpdateName)
         .when(commandLine)
-        .newUpdateMetalakeName(
-            GravitinoCommandLine.DEFAULT_URL, false, false, "metalake_demo", 
"new_name");
+        .newUpdateMetalakeName(any(CommandContext.class), eq("metalake_demo"), 
eq("new_name"));
     doReturn(mockUpdateName).when(mockUpdateName).validate();
     commandLine.handleCommandLine();
     verify(mockUpdateName).handle();
@@ -367,8 +366,7 @@ class TestMetalakeCommands {
                 mockCommandLine, mockOptions, CommandEntities.METALAKE, 
CommandActions.UPDATE));
     doReturn(mockUpdateName)
         .when(commandLine)
-        .newUpdateMetalakeName(
-            GravitinoCommandLine.DEFAULT_URL, false, true, "metalake_demo", 
"new_name");
+        .newUpdateMetalakeName(any(CommandContext.class), eq("metalake_demo"), 
eq("new_name"));
     doReturn(mockUpdateName).when(mockUpdateName).validate();
     commandLine.handleCommandLine();
     verify(mockUpdateName).handle();
@@ -386,7 +384,7 @@ class TestMetalakeCommands {
                 mockCommandLine, mockOptions, CommandEntities.METALAKE, 
CommandActions.UPDATE));
     doReturn(mockEnable)
         .when(commandLine)
-        .newMetalakeEnable(GravitinoCommandLine.DEFAULT_URL, false, 
"metalake_demo", false);
+        .newMetalakeEnable(any(CommandContext.class), eq("metalake_demo"), 
eq(false));
     doReturn(mockEnable).when(mockEnable).validate();
     commandLine.handleCommandLine();
     verify(mockEnable).handle();
@@ -405,7 +403,7 @@ class TestMetalakeCommands {
                 mockCommandLine, mockOptions, CommandEntities.METALAKE, 
CommandActions.UPDATE));
     doReturn(mockEnable)
         .when(commandLine)
-        .newMetalakeEnable(GravitinoCommandLine.DEFAULT_URL, false, 
"metalake_demo", true);
+        .newMetalakeEnable(any(CommandContext.class), eq("metalake_demo"), 
eq(true));
     doReturn(mockEnable).when(mockEnable).validate();
     commandLine.handleCommandLine();
     verify(mockEnable).handle();
@@ -424,7 +422,7 @@ class TestMetalakeCommands {
                 mockCommandLine, mockOptions, CommandEntities.METALAKE, 
CommandActions.UPDATE));
     doReturn(mockDisable)
         .when(commandLine)
-        .newMetalakeDisable(GravitinoCommandLine.DEFAULT_URL, false, 
"metalake_demo");
+        .newMetalakeDisable(any(CommandContext.class), eq("metalake_demo"));
     doReturn(mockDisable).when(mockDisable).validate();
     commandLine.handleCommandLine();
     verify(mockDisable).handle();
@@ -446,9 +444,9 @@ class TestMetalakeCommands {
 
     Assert.assertThrows(RuntimeException.class, 
commandLine::handleCommandLine);
     verify(commandLine, never())
-        .newMetalakeEnable(GravitinoCommandLine.DEFAULT_URL, false, 
"metalake_demo", false);
+        .newMetalakeEnable(any(CommandContext.class), eq("metalake_demo"), 
eq(false));
     verify(commandLine, never())
-        .newMetalakeEnable(GravitinoCommandLine.DEFAULT_URL, false, 
"metalake_demo", false);
+        .newMetalakeEnable(any(CommandContext.class), eq("metalake_demo"), 
eq(false));
     
assertTrue(errContent.toString().contains(ErrorMessages.INVALID_ENABLE_DISABLE));
   }
 }

Reply via email to