@Test public void falseBooleanParameters() throws Exception { String[] args = new String[]{ "--promptForNonLocalDatabase=false", "update", }; Main cli = new Main(); cli.parseOptions(args); assertEquals(Boolean.FALSE, cli.promptForNonLocalDatabase); assertEquals("update", cli.command); }
protected void parseOptions(String[] args) throws CommandLineParsingException { args = fixupArgs(args); boolean seenCommand = false; for (String arg : args) { if (isCommand(arg)) { this.command = arg; if (this.command.equalsIgnoreCase("migrate")) { this.command = "update"; } else if (this.command.equalsIgnoreCase("migrateSQL")) { this.command = "updateSQL"; } seenCommand = true; } else if (seenCommand) { if (arg.startsWith("-D")) { String[] splitArg = splitArg(arg); String attributeName = splitArg[0].replaceFirst("^-D", ""); String value = splitArg[1]; changeLogParameters.put(attributeName, value); } else { commandParams.add(arg); } } else if (arg.startsWith("--")) { String[] splitArg = splitArg(arg); String attributeName = splitArg[0]; String value = splitArg[1]; try { Field field = getClass().getDeclaredField(attributeName); if (field.getType().equals(Boolean.class)) { field.set(this, Boolean.valueOf(value)); } else { field.set(this, value); } } catch (Exception e) { throw new CommandLineParsingException("Unknown parameter: '" + attributeName + "'"); } } else { throw new CommandLineParsingException("Unexpected value " + arg + ": parameters must start with a '--'"); } } }
Main { protected void parseOptions(String[] args) throws CommandLineParsingException { args = fixupArgs(args); boolean seenCommand = false; for (String arg : args) { if (isCommand(arg)) { this.command = arg; if (this.command.equalsIgnoreCase("migrate")) { this.command = "update"; } else if (this.command.equalsIgnoreCase("migrateSQL")) { this.command = "updateSQL"; } seenCommand = true; } else if (seenCommand) { if (arg.startsWith("-D")) { String[] splitArg = splitArg(arg); String attributeName = splitArg[0].replaceFirst("^-D", ""); String value = splitArg[1]; changeLogParameters.put(attributeName, value); } else { commandParams.add(arg); } } else if (arg.startsWith("--")) { String[] splitArg = splitArg(arg); String attributeName = splitArg[0]; String value = splitArg[1]; try { Field field = getClass().getDeclaredField(attributeName); if (field.getType().equals(Boolean.class)) { field.set(this, Boolean.valueOf(value)); } else { field.set(this, value); } } catch (Exception e) { throw new CommandLineParsingException("Unknown parameter: '" + attributeName + "'"); } } else { throw new CommandLineParsingException("Unexpected value " + arg + ": parameters must start with a '--'"); } } } }
Main { protected void parseOptions(String[] args) throws CommandLineParsingException { args = fixupArgs(args); boolean seenCommand = false; for (String arg : args) { if (isCommand(arg)) { this.command = arg; if (this.command.equalsIgnoreCase("migrate")) { this.command = "update"; } else if (this.command.equalsIgnoreCase("migrateSQL")) { this.command = "updateSQL"; } seenCommand = true; } else if (seenCommand) { if (arg.startsWith("-D")) { String[] splitArg = splitArg(arg); String attributeName = splitArg[0].replaceFirst("^-D", ""); String value = splitArg[1]; changeLogParameters.put(attributeName, value); } else { commandParams.add(arg); } } else if (arg.startsWith("--")) { String[] splitArg = splitArg(arg); String attributeName = splitArg[0]; String value = splitArg[1]; try { Field field = getClass().getDeclaredField(attributeName); if (field.getType().equals(Boolean.class)) { field.set(this, Boolean.valueOf(value)); } else { field.set(this, value); } } catch (Exception e) { throw new CommandLineParsingException("Unknown parameter: '" + attributeName + "'"); } } else { throw new CommandLineParsingException("Unexpected value " + arg + ": parameters must start with a '--'"); } } } Main(); }
Main { protected void parseOptions(String[] args) throws CommandLineParsingException { args = fixupArgs(args); boolean seenCommand = false; for (String arg : args) { if (isCommand(arg)) { this.command = arg; if (this.command.equalsIgnoreCase("migrate")) { this.command = "update"; } else if (this.command.equalsIgnoreCase("migrateSQL")) { this.command = "updateSQL"; } seenCommand = true; } else if (seenCommand) { if (arg.startsWith("-D")) { String[] splitArg = splitArg(arg); String attributeName = splitArg[0].replaceFirst("^-D", ""); String value = splitArg[1]; changeLogParameters.put(attributeName, value); } else { commandParams.add(arg); } } else if (arg.startsWith("--")) { String[] splitArg = splitArg(arg); String attributeName = splitArg[0]; String value = splitArg[1]; try { Field field = getClass().getDeclaredField(attributeName); if (field.getType().equals(Boolean.class)) { field.set(this, Boolean.valueOf(value)); } else { field.set(this, value); } } catch (Exception e) { throw new CommandLineParsingException("Unknown parameter: '" + attributeName + "'"); } } else { throw new CommandLineParsingException("Unexpected value " + arg + ": parameters must start with a '--'"); } } } Main(); static void main(String args[]); boolean isWindows(); }
Main { protected void parseOptions(String[] args) throws CommandLineParsingException { args = fixupArgs(args); boolean seenCommand = false; for (String arg : args) { if (isCommand(arg)) { this.command = arg; if (this.command.equalsIgnoreCase("migrate")) { this.command = "update"; } else if (this.command.equalsIgnoreCase("migrateSQL")) { this.command = "updateSQL"; } seenCommand = true; } else if (seenCommand) { if (arg.startsWith("-D")) { String[] splitArg = splitArg(arg); String attributeName = splitArg[0].replaceFirst("^-D", ""); String value = splitArg[1]; changeLogParameters.put(attributeName, value); } else { commandParams.add(arg); } } else if (arg.startsWith("--")) { String[] splitArg = splitArg(arg); String attributeName = splitArg[0]; String value = splitArg[1]; try { Field field = getClass().getDeclaredField(attributeName); if (field.getType().equals(Boolean.class)) { field.set(this, Boolean.valueOf(value)); } else { field.set(this, value); } } catch (Exception e) { throw new CommandLineParsingException("Unknown parameter: '" + attributeName + "'"); } } else { throw new CommandLineParsingException("Unexpected value " + arg + ": parameters must start with a '--'"); } } } Main(); static void main(String args[]); boolean isWindows();  }