Handle missing plugin name in remove command
Today if a user invokes the remove plugin command without specifying the name of a plugin to remove, we arrive at a null pointer exception. This commit adds logic to cleanly handle this situation and provide clear feedback to the user. Relates #22930
This commit is contained in:
parent
58c34f0da9
commit
365d33efe3
|
@ -57,6 +57,10 @@ class RemovePluginCommand extends EnvironmentAwareCommand {
|
||||||
|
|
||||||
// pkg private for testing
|
// pkg private for testing
|
||||||
void execute(Terminal terminal, String pluginName, Environment env) throws Exception {
|
void execute(Terminal terminal, String pluginName, Environment env) throws Exception {
|
||||||
|
if (pluginName == null) {
|
||||||
|
throw new UserException(ExitCodes.USAGE, "plugin name is required");
|
||||||
|
}
|
||||||
|
|
||||||
terminal.println("-> Removing " + Strings.coalesceToEmpty(pluginName) + "...");
|
terminal.println("-> Removing " + Strings.coalesceToEmpty(pluginName) + "...");
|
||||||
|
|
||||||
final Path pluginDir = env.pluginsFile().resolve(pluginName);
|
final Path pluginDir = env.pluginsFile().resolve(pluginName);
|
||||||
|
|
|
@ -153,6 +153,12 @@ public class RemovePluginCommandTests extends ESTestCase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testMissingPluginName() throws Exception {
|
||||||
|
UserException e = expectThrows(UserException.class, () -> removePlugin(null, home));
|
||||||
|
assertEquals(ExitCodes.USAGE, e.exitCode);
|
||||||
|
assertEquals("plugin name is required", e.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
private String expectedConfigDirPreservedMessage(final Path configDir) {
|
private String expectedConfigDirPreservedMessage(final Path configDir) {
|
||||||
return "-> Preserving plugin config files [" + configDir + "] in case of upgrade, delete manually if not needed";
|
return "-> Preserving plugin config files [" + configDir + "] in case of upgrade, delete manually if not needed";
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue