From f902f2fa9a2a4edd650fc8ee804e4064b82b6550 Mon Sep 17 00:00:00 2001 From: Justin Mclean Date: Tue, 26 Nov 2024 20:38:58 +1100 Subject: [PATCH] [Minor] Updates to delete multiple tags in Gravitino CLI (#5666) ### What changes were proposed in this pull request? Fixed some display issues and minor improvements to code. ### Why are the changes needed? To have display messages more consistent. Fix: # N/A ### Does this PR introduce _any_ user-facing change? N/A ### How was this patch tested? Tested locally. --------- Co-authored-by: sunxiaojian --- .../org/apache/gravitino/cli/GravitinoCommandLine.java | 4 +++- .../org/apache/gravitino/cli/commands/CreateTag.java | 2 +- .../org/apache/gravitino/cli/commands/DeleteTag.java | 10 +++------- .../org/apache/gravitino/cli/commands/TagEntity.java | 2 +- .../org/apache/gravitino/cli/commands/UntagEntity.java | 8 ++++++-- 5 files changed, 14 insertions(+), 12 deletions(-) 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 14e2cd20e13..1cdbfaf25a8 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 @@ -370,7 +370,9 @@ protected void handleTagCommand() { String metalake = name.getMetalakeName(); String[] tags = line.getOptionValues(GravitinoOptions.TAG); - tags = tags != null ? Arrays.stream(tags).distinct().toArray(String[]::new) : null; + if (tags != null) { + tags = Arrays.stream(tags).distinct().toArray(String[]::new); + } if (CommandActions.DETAILS.equals(command)) { newTagDetails(url, ignore, metalake, getOneTag(tags)).handle(); } else if (CommandActions.LIST.equals(command)) { diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/CreateTag.java b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/CreateTag.java index 004254c16df..61406c000c3 100644 --- a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/CreateTag.java +++ b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/CreateTag.java @@ -75,7 +75,7 @@ private void handleOnlyOneTag() { return; } - System.out.println(tags[0] + " created"); + System.out.println("Tag " + tags[0] + " created"); } private void handleMultipleTags() { 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 0db4a897610..2d930560cc5 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 @@ -90,17 +90,13 @@ private void handleMultipleTags() { if (deleted.size() < tags.length) { List remaining = Arrays.asList(tags); remaining.removeAll(deleted); - System.out.println("Tags " + String.join(",", deleted) + " not deleted."); + System.out.println("Tags " + String.join(",", remaining) + " not deleted."); } } private void handleOnlyOneTag() { boolean deleted = false; - if (!AreYouSure.really(force)) { - return; - } - try { GravitinoClient client = buildClient(metalake); deleted = client.deleteTag(tags[0]); @@ -116,9 +112,9 @@ private void handleOnlyOneTag() { } if (deleted) { - System.out.println(tags[0] + " deleted."); + System.out.println("Tag " + tags[0] + " deleted."); } else { - System.out.println(tags[0] + " not deleted."); + System.out.println("Tag " + tags[0] + " not deleted."); } } } diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/TagEntity.java b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/TagEntity.java index ed474c78401..b6f7c3210e0 100644 --- a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/TagEntity.java +++ b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/TagEntity.java @@ -105,6 +105,6 @@ public void handle() { String all = String.join(",", tagsToAdd); - System.out.println(entity + " tagged with " + all); + System.out.println(entity + " now tagged with " + all); } } diff --git a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/UntagEntity.java b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/UntagEntity.java index 77437dafc21..3b9771bc8fe 100644 --- a/clients/cli/src/main/java/org/apache/gravitino/cli/commands/UntagEntity.java +++ b/clients/cli/src/main/java/org/apache/gravitino/cli/commands/UntagEntity.java @@ -109,7 +109,11 @@ public void handle() { all = "nothing"; } - System.out.println( - entity + " removed tag " + String.join(",", tags) + " now tagged with " + all); + if (tags.length > 1) { + System.out.println( + entity + " removed tags " + String.join(",", tags) + " now tagged with " + all); + } else { + System.out.println(entity + " removed tag " + tags[0].toString() + " now tagged with " + all); + } } }