Skip to content

Commit 52a71d9

Browse files
author
Yogesh Gaikwad
committed
CLI: MultiCommand#close address review comments
CLI now depends on elasticsearch-core, for IOUtils. Closes elastic#28953
1 parent 63c3656 commit 52a71d9

File tree

2 files changed

+5
-40
lines changed

2 files changed

+5
-40
lines changed

server/cli/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ archivesBaseName = 'elasticsearch-cli'
3636

3737
dependencies {
3838
compile 'net.sf.jopt-simple:jopt-simple:5.0.2'
39+
compile "org.elasticsearch:elasticsearch-core:${version}"
3940
}
4041

4142
test.enabled = false

server/cli/src/main/java/org/elasticsearch/cli/MultiCommand.java

Lines changed: 4 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
import joptsimple.NonOptionArgumentSpec;
2929
import joptsimple.OptionSet;
3030

31+
import org.elasticsearch.core.internal.io.IOUtils;
32+
3133
/**
3234
* A cli tool which is made up of multiple subcommands.
3335
*/
@@ -78,46 +80,8 @@ protected void execute(Terminal terminal, OptionSet options) throws Exception {
7880
}
7981

8082
@Override
81-
public void close() throws IOException, RuntimeException {
82-
Throwable th = null;
83-
for (Closeable object : subcommands.values()) {
84-
try {
85-
if (object != null) {
86-
object.close();
87-
}
88-
} catch (Throwable t) {
89-
addSuppressed(th, t);
90-
if (th == null) {
91-
th = t;
92-
}
93-
}
94-
}
95-
if (th != null) {
96-
throw reThrowAlways(th);
97-
}
83+
public void close() throws IOException {
84+
IOUtils.close(subcommands.values());
9885
}
9986

100-
// Following methods are similar to IOUtils,
101-
// avoiding lucene dependency in CLI.
102-
private static void addSuppressed(Throwable t, Throwable suppressed) {
103-
if (t != null && suppressed != null) {
104-
t.addSuppressed(suppressed);
105-
}
106-
}
107-
108-
private static Error reThrowAlways(Throwable th) throws IOException, RuntimeException {
109-
if (th instanceof IOException) {
110-
throw (IOException) th;
111-
}
112-
113-
if (th instanceof RuntimeException) {
114-
throw (RuntimeException) th;
115-
}
116-
117-
if (th instanceof Error) {
118-
throw (Error) th;
119-
}
120-
121-
throw new RuntimeException(th);
122-
}
12387
}

0 commit comments

Comments
 (0)