@Test public void testScriptPathIsMandatory() throws Exception { RunScriptCommand command = new RunScriptCommand(); int rc = command.run(null, out, err, Lists.<String>newArrayList()); assertThat(rc, is(-1)); assertThat(errBytes.toString(), containsString("Please specify a script file to be executed.")); }
@Override public int run(InputStream in, PrintStream out, PrintStream err, List<String> args) throws Exception { OptionSet optionSet = parser.parse(args.toArray(new String[0])); if (!optionSet.has(scriptOption)) { err.println("Please specify a script file to be executed."); err.println("Get more help: whirr help " + getName()); return -1; } if (!(new File(optionSet.valueOf(scriptOption))).exists()) { err.printf("Script file '%s' not found.", optionSet.valueOf(scriptOption)); err.println("Get more help: whirr help " + getName()); return -2; } try { ClusterSpec clusterSpec = getClusterSpec(optionSet); String[] ids = null; String[] roles = null; if (optionSet.has(instancesOption)) { ids = optionSet.valueOf(instancesOption).split(","); } if (optionSet.has(rolesOption)) { roles = optionSet.valueOf(rolesOption).split(","); } printProviderInfo(out, err, clusterSpec, optionSet); return run(in, out, err, clusterSpec, ids, roles, optionSet.valueOf(scriptOption)); } catch (IllegalArgumentException e) { printErrorAndHelpHint(err, e); return -3; } }
RunScriptCommand extends AbstractClusterCommand { @Override public int run(InputStream in, PrintStream out, PrintStream err, List<String> args) throws Exception { OptionSet optionSet = parser.parse(args.toArray(new String[0])); if (!optionSet.has(scriptOption)) { err.println("Please specify a script file to be executed."); err.println("Get more help: whirr help " + getName()); return -1; } if (!(new File(optionSet.valueOf(scriptOption))).exists()) { err.printf("Script file '%s' not found.", optionSet.valueOf(scriptOption)); err.println("Get more help: whirr help " + getName()); return -2; } try { ClusterSpec clusterSpec = getClusterSpec(optionSet); String[] ids = null; String[] roles = null; if (optionSet.has(instancesOption)) { ids = optionSet.valueOf(instancesOption).split(","); } if (optionSet.has(rolesOption)) { roles = optionSet.valueOf(rolesOption).split(","); } printProviderInfo(out, err, clusterSpec, optionSet); return run(in, out, err, clusterSpec, ids, roles, optionSet.valueOf(scriptOption)); } catch (IllegalArgumentException e) { printErrorAndHelpHint(err, e); return -3; } } }
RunScriptCommand extends AbstractClusterCommand { @Override public int run(InputStream in, PrintStream out, PrintStream err, List<String> args) throws Exception { OptionSet optionSet = parser.parse(args.toArray(new String[0])); if (!optionSet.has(scriptOption)) { err.println("Please specify a script file to be executed."); err.println("Get more help: whirr help " + getName()); return -1; } if (!(new File(optionSet.valueOf(scriptOption))).exists()) { err.printf("Script file '%s' not found.", optionSet.valueOf(scriptOption)); err.println("Get more help: whirr help " + getName()); return -2; } try { ClusterSpec clusterSpec = getClusterSpec(optionSet); String[] ids = null; String[] roles = null; if (optionSet.has(instancesOption)) { ids = optionSet.valueOf(instancesOption).split(","); } if (optionSet.has(rolesOption)) { roles = optionSet.valueOf(rolesOption).split(","); } printProviderInfo(out, err, clusterSpec, optionSet); return run(in, out, err, clusterSpec, ids, roles, optionSet.valueOf(scriptOption)); } catch (IllegalArgumentException e) { printErrorAndHelpHint(err, e); return -3; } } RunScriptCommand();  RunScriptCommand(ClusterControllerFactory factory);  RunScriptCommand(ClusterControllerFactory factory,
                          ClusterStateStoreFactory stateStoreFactory); }
RunScriptCommand extends AbstractClusterCommand { @Override public int run(InputStream in, PrintStream out, PrintStream err, List<String> args) throws Exception { OptionSet optionSet = parser.parse(args.toArray(new String[0])); if (!optionSet.has(scriptOption)) { err.println("Please specify a script file to be executed."); err.println("Get more help: whirr help " + getName()); return -1; } if (!(new File(optionSet.valueOf(scriptOption))).exists()) { err.printf("Script file '%s' not found.", optionSet.valueOf(scriptOption)); err.println("Get more help: whirr help " + getName()); return -2; } try { ClusterSpec clusterSpec = getClusterSpec(optionSet); String[] ids = null; String[] roles = null; if (optionSet.has(instancesOption)) { ids = optionSet.valueOf(instancesOption).split(","); } if (optionSet.has(rolesOption)) { roles = optionSet.valueOf(rolesOption).split(","); } printProviderInfo(out, err, clusterSpec, optionSet); return run(in, out, err, clusterSpec, ids, roles, optionSet.valueOf(scriptOption)); } catch (IllegalArgumentException e) { printErrorAndHelpHint(err, e); return -3; } } RunScriptCommand();  RunScriptCommand(ClusterControllerFactory factory);  RunScriptCommand(ClusterControllerFactory factory,
                          ClusterStateStoreFactory stateStoreFactory); @Override int run(InputStream in, PrintStream out, PrintStream err,
                 List<String> args); int run(InputStream in, PrintStream out, PrintStream err,
                 ClusterSpec clusterSpec, String[] instances, String[] roles,
                 String fileName); @Override void printUsage(PrintStream stream); }
RunScriptCommand extends AbstractClusterCommand { @Override public int run(InputStream in, PrintStream out, PrintStream err, List<String> args) throws Exception { OptionSet optionSet = parser.parse(args.toArray(new String[0])); if (!optionSet.has(scriptOption)) { err.println("Please specify a script file to be executed."); err.println("Get more help: whirr help " + getName()); return -1; } if (!(new File(optionSet.valueOf(scriptOption))).exists()) { err.printf("Script file '%s' not found.", optionSet.valueOf(scriptOption)); err.println("Get more help: whirr help " + getName()); return -2; } try { ClusterSpec clusterSpec = getClusterSpec(optionSet); String[] ids = null; String[] roles = null; if (optionSet.has(instancesOption)) { ids = optionSet.valueOf(instancesOption).split(","); } if (optionSet.has(rolesOption)) { roles = optionSet.valueOf(rolesOption).split(","); } printProviderInfo(out, err, clusterSpec, optionSet); return run(in, out, err, clusterSpec, ids, roles, optionSet.valueOf(scriptOption)); } catch (IllegalArgumentException e) { printErrorAndHelpHint(err, e); return -3; } } RunScriptCommand();  RunScriptCommand(ClusterControllerFactory factory);  RunScriptCommand(ClusterControllerFactory factory,
                          ClusterStateStoreFactory stateStoreFactory); @Override int run(InputStream in, PrintStream out, PrintStream err,
                 List<String> args); int run(InputStream in, PrintStream out, PrintStream err,
                 ClusterSpec clusterSpec, String[] instances, String[] roles,
                 String fileName); @Override void printUsage(PrintStream stream);  }