Skip to content

Commit

Permalink
PluginManager fails with unknown command when passing url or verbose …
Browse files Browse the repository at this point in the history
…parameters

Closes #3245.
  • Loading branch information
dadoonet committed Jun 26, 2013
1 parent 0d16ccc commit 5189b2b
Showing 1 changed file with 73 additions and 56 deletions.
129 changes: 73 additions & 56 deletions src/main/java/org/elasticsearch/plugins/PluginManager.java
Expand Up @@ -46,6 +46,12 @@
*
*/
public class PluginManager {
public static final class ACTION {
public static final int NONE = 0;
public static final int INSTALL = 1;
public static final int REMOVE = 2;
public static final int LIST = 3;
}

private final Environment environment;

Expand Down Expand Up @@ -309,69 +315,80 @@ public static void main(String[] args) {

String url = null;
boolean verbose = false;
for (int i = 0; i < args.length; i++) {
String command = args[i];
if ("-u".equals(command) || "--url".equals(command)
// Deprecated commands
|| "url".equals(command) || "-url".equals(command)) {
try {
url = args[i + 1];
} catch (Exception e) {
displayHelp("Error while installing plugin, reason: " + e.getClass().getSimpleName() +
": " + e.getMessage());
System.exit(1);
}
} else if ("-v".equals(command) || "--v".equals(command)
|| "verbose".equals(command) || "-verbose".equals(command)) {
verbose = true;
}
}


PluginManager pluginManager = new PluginManager(initialSettings.v2(), url);
String pluginName = null;
int action = ACTION.NONE;

if (args.length < 1) {
displayHelp(null);
}
for (int c = 0; c < args.length; c++) {
String command = args[c];
if (command.equals("-i") || command.equals("--install")
// Deprecated commands
|| command.equals("install") || command.equals("-install")) {
String pluginName = null;
try {

try {
for (int c = 0; c < args.length; c++) {
String command = args[c];
if ("-u".equals(command) || "--url".equals(command)
// Deprecated commands
|| "url".equals(command) || "-url".equals(command)) {
url = args[++c];
} else if ("-v".equals(command) || "--v".equals(command)
|| "verbose".equals(command) || "-verbose".equals(command)) {
verbose = true;
} else if (command.equals("-i") || command.equals("--install")
// Deprecated commands
|| command.equals("install") || command.equals("-install")) {
pluginName = args[++c];
System.out.println("-> Installing " + pluginName + "...");
pluginManager.downloadAndExtract(pluginName, verbose);
} catch (IOException e) {
System.out.println("Failed to install " + pluginName + ", reason: " + e.getMessage());
} catch (Exception e) {
displayHelp("Error while installing plugin, reason: " + e.getClass().getSimpleName() +
": " + e.getMessage());
System.exit(1);
}
} else if (command.equals("-r") || command.equals("--remove")
// Deprecated commands
|| command.equals("remove") || command.equals("-remove")) {
String pluginName = null;
try {
action = ACTION.INSTALL;

} else if (command.equals("-r") || command.equals("--remove")
// Deprecated commands
|| command.equals("remove") || command.equals("-remove")) {
pluginName = args[++c];
System.out.println("-> Removing " + pluginName + " ");
pluginManager.removePlugin(pluginName);
} catch (IOException e) {
System.out.println("Failed to remove " + pluginName + ", reason: " + e.getMessage());
} catch (Exception e) {
displayHelp("Error while removing plugin, reason: " + e.getClass().getSimpleName() +
": " + e.getMessage());
action = ACTION.REMOVE;
} else if (command.equals("-l") || command.equals("--list")) {
action = ACTION.LIST;
} else if (command.equals("-h") || command.equals("--help")) {
displayHelp(null);
} else {
displayHelp("Command [" + args[c] + "] unknown.");
// Unknown command. We break...
System.exit(1);
}
} else if (command.equals("-l") || command.equals("--list")) {
pluginManager.listInstalledPlugins();
} else if (command.equals("-h") || command.equals("--help")) {
displayHelp(null);
} else {
displayHelp("Command [" + args[c] + "] unknown.");
// Unknown command. We break...
System.exit(1);
}
} catch (Exception e) {
displayHelp("Error while parsing options: " + e.getClass().getSimpleName() +
": " + e.getMessage());
System.exit(1);
}

if (action > ACTION.NONE) {
PluginManager pluginManager = new PluginManager(initialSettings.v2(), url);

switch (action) {
case ACTION.INSTALL:
try {
System.out.println("-> Installing " + pluginName + "...");
pluginManager.downloadAndExtract(pluginName, verbose);
} catch (IOException e) {
System.out.println("Failed to install " + pluginName + ", reason: " + e.getMessage());
} catch (Exception e) {
displayHelp("Error while installing plugin, reason: " + e.getClass().getSimpleName() +
": " + e.getMessage());
System.exit(1);
}
break;
case ACTION.REMOVE:
try {
System.out.println("-> Removing " + pluginName + " ");
pluginManager.removePlugin(pluginName);
} catch (IOException e) {
System.out.println("Failed to remove " + pluginName + ", reason: " + e.getMessage());
} catch (Exception e) {
displayHelp("Error while removing plugin, reason: " + e.getClass().getSimpleName() +
": " + e.getMessage());
}
break;
case ACTION.LIST:
pluginManager.listInstalledPlugins();
break;
}
}
}
Expand Down

0 comments on commit 5189b2b

Please sign in to comment.