commandLine.add(LocatorLauncher.Command.START.getName());
/** * Displays help for the specified Locator launcher command to standard err. If the Locator * launcher command is unspecified, then usage information is displayed instead. * * @param command the Locator launcher command in which to display help information. * @see #usage() */ public void help(final Command command) { if (Command.isUnspecified(command)) { usage(); } else { info(wrap(helpMap.get(command.getName()), 80, "")); info("\n\nusage: \n\n"); info(wrap("> java ... " + getClass().getName() + " " + usageMap.get(command), 80, "\t\t")); info("\n\noptions: \n\n"); for (String option : command.getOptions()) { info(wrap("--" + option + ": " + helpMap.get(option) + "\n", 80, "\t")); } info("\n\n"); } }
/** * Iterates the list of arguments in search of the Locator's GemFire member name. If the * argument does not start with '-' or is not the name of a Locator launcher command, then the * value is presumed to be the member name for the Locator in GemFire. * * @param args the array of arguments from which to search for the Locator's member name in * GemFire. * @see org.apache.geode.distributed.LocatorLauncher.Command#isCommand(String) * @see #parseArguments(String...) */ protected void parseMemberName(final String... args) { if (args != null) { for (String arg : args) { if (!(arg.startsWith(OPTION_PREFIX) || Command.isCommand(arg))) { setMemberName(arg); break; } } } }
@Test public void testLocatorCommandLineWithRestAPI() throws Exception { LocatorLauncher locatorLauncher = new LocatorLauncher.Builder().setCommand(LocatorLauncher.Command.START) .setMemberName("testLocatorCommandLineWithRestAPI").setBindAddress("localhost") .setPort(11111).build(); Properties gemfireProperties = new Properties(); gemfireProperties.setProperty(HTTP_SERVICE_PORT, "8089"); gemfireProperties.setProperty(HTTP_SERVICE_BIND_ADDRESS, "localhost"); String[] commandLineElements = startLocatorCommand.createStartLocatorCommandLine(locatorLauncher, null, null, gemfireProperties, null, false, new String[0], null, null); assertNotNull(commandLineElements); assertTrue(commandLineElements.length > 0); Set<String> expectedCommandLineElements = new HashSet<>(6); expectedCommandLineElements.add(locatorLauncher.getCommand().getName()); expectedCommandLineElements.add(locatorLauncher.getMemberName().toLowerCase()); expectedCommandLineElements.add(String.format("--port=%1$d", locatorLauncher.getPort())); expectedCommandLineElements .add("-d" + DistributionConfig.GEMFIRE_PREFIX + "" + HTTP_SERVICE_PORT + "=" + "8089"); expectedCommandLineElements.add("-d" + DistributionConfig.GEMFIRE_PREFIX + "" + HTTP_SERVICE_BIND_ADDRESS + "=" + "localhost"); for (String commandLineElement : commandLineElements) { expectedCommandLineElements.remove(commandLineElement.toLowerCase()); } assertTrue(String.format("Expected ([]); but was (%1$s)", expectedCommandLineElements), expectedCommandLineElements.isEmpty()); }
/** * Iterates the list of arguments in search of the target Locator launcher command. * * @param args an array of arguments from which to search for the Locator launcher command. * @see org.apache.geode.distributed.LocatorLauncher.Command#valueOfName(String) * @see #parseArguments(String...) */ protected void parseCommand(final String... args) { // search the list of arguments for the command; technically, the command should be the first // argument in the // list, but does it really matter? stop after we find one valid command. if (args != null) { for (String arg : args) { final Command command = Command.valueOfName(arg); if (command != null) { setCommand(command); break; } } } }
/** * Looks up a Locator launcher command by name. The equality comparison on name is * case-insensitive. * * @param name a String value indicating the name of the Locator launcher command. * @return an enumerated type representing the command name or null if the no such command with * the specified name exists. */ public static Command valueOfName(final String name) { for (Command command : values()) { if (command.getName().equalsIgnoreCase(name)) { return command; } } return null; }
@Test public void parseCommandWithTwoCommandsWithSwitchesUsesFirstCommand() throws Exception { Builder builder = new Builder(); builder.parseCommand("--opt", "START", "-o", Command.STATUS.getName()); assertThat(builder.getCommand()).isEqualTo(Command.START); }
/** * Determines whether the given Locator launcher command has been properly specified. The * command is deemed unspecified if the reference is null or the Command is UNSPECIFIED. * * @param command the Locator launcher command. * @return a boolean value indicating whether the Locator launcher command is unspecified. * @see Command#UNSPECIFIED */ public static boolean isUnspecified(final Command command) { return (command == null || command.isUnspecified()); }
/** * Determines whether the specified name refers to a valid Locator launcher command, as defined * by this enumerated type. * * @param name a String value indicating the potential name of a Locator launcher command. * @return a boolean indicating whether the specified name for a Locator launcher command is * valid. */ public static boolean isCommand(final String name) { return (valueOfName(name) != null); }
@Test public void parseMemberNameWithCommandAndOptionsResultsInNull() throws Exception { Builder builder = new Builder(); builder.parseMemberName(Command.START.getName(), "--opt", "-o"); assertThat(builder.getMemberName()).isNull(); }
@Test public void parseCommandWithTwoCommandsWithoutSwitchesUsesFirstCommand() throws Exception { Builder builder = new Builder(); builder.parseCommand("START", Command.STATUS.getName()); assertThat(builder.getCommand()).isEqualTo(Command.START); }
/** * Gets the String representation of this Locator launcher command. * * @return a String value representing this Locator launcher command. */ @Override public String toString() { return getName(); } }
/** * Determines whether this Locator launcher command has the specified command-line option. * * @param option a String indicating the name of the command-line option to this command. * @return a boolean value indicating whether this command has the specified named command-line * option. */ public boolean hasOption(final String option) { return getOptions().contains(lowerCase(option)); }
@Test public void parseCommandWithStartResultsInStartCommand() throws Exception { Builder builder = new Builder(); builder.parseCommand(Command.START.getName()); assertThat(builder.getCommand()).isEqualTo(Command.START); }