Skip to content

Commit 39770da

Browse files
author
Yogesh Gaikwad
committed
CLI Command: MultiCommand must close subcommands to release resources properly
Changes done to override close method and call close on subcommands. Closes elastic#28953
1 parent 17fc07a commit 39770da

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
package org.elasticsearch.cli;
2121

22+
import java.io.IOException;
2223
import java.util.Arrays;
2324
import java.util.LinkedHashMap;
2425
import java.util.Map;
@@ -74,4 +75,16 @@ protected void execute(Terminal terminal, OptionSet options) throws Exception {
7475
}
7576
subcommand.mainWithoutErrorHandling(Arrays.copyOfRange(args, 1, args.length), terminal);
7677
}
78+
79+
@Override
80+
public void close() throws IOException {
81+
if (subcommands.isEmpty()) {
82+
throw new IllegalStateException("No subcommands configured");
83+
}
84+
for (Command command : subcommands.values()) {
85+
if (command != null) {
86+
command.close();
87+
}
88+
}
89+
}
7790
}

0 commit comments

Comments
 (0)