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:
Chris Buonocore 2017-02-02 16:39:56 -08:00 committed by Jason Tedor
parent 58c34f0da9
commit 365d33efe3
2 changed files with 10 additions and 0 deletions

View File

@ -57,6 +57,10 @@ class RemovePluginCommand extends EnvironmentAwareCommand {
// pkg private for testing
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) + "...");
final Path pluginDir = env.pluginsFile().resolve(pluginName);

View File

@ -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) {
return "-> Preserving plugin config files [" + configDir + "] in case of upgrade, delete manually if not needed";
}