List of usage examples for org.apache.commons.cli Option UNINITIALIZED
int UNINITIALIZED
To view the source code for org.apache.commons.cli Option UNINITIALIZED.
Click Source Link
From source file:ch.cyberduck.cli.TerminalOptionsInputValidator.java
public boolean validate(final CommandLine input) { for (Option o : input.getOptions()) { if (Option.UNINITIALIZED == o.getArgs()) { continue; }/*from ww w .j av a2 s. c om*/ if (o.hasOptionalArg()) { continue; } if (o.getArgs() != o.getValuesList().size()) { console.printf("Missing argument for option %s%n", o.getLongOpt()); return false; } } final TerminalAction action = TerminalActionFinder.get(input); if (null == action) { console.printf("%s%n", "Missing argument"); return false; } if (input.hasOption(TerminalOptionsBuilder.Params.existing.name())) { final String arg = input.getOptionValue(TerminalOptionsBuilder.Params.existing.name()); if (null == TransferAction.forName(arg)) { final Set<TransferAction> actions = new HashSet<TransferAction>( TransferAction.forTransfer(Transfer.Type.download)); actions.add(TransferAction.cancel); console.printf("Invalid argument '%s' for option %s. Must be one of %s%n", arg, TerminalOptionsBuilder.Params.existing.name(), Arrays.toString(actions.toArray())); return false; } switch (action) { case download: if (!validate(arg, Transfer.Type.download)) { return false; } break; case upload: if (!validate(arg, Transfer.Type.upload)) { return false; } break; case synchronize: if (!validate(arg, Transfer.Type.sync)) { return false; } break; case copy: if (!validate(arg, Transfer.Type.copy)) { return false; } break; } } // Validate arguments switch (action) { case list: case download: if (!validate(input.getOptionValue(action.name()))) { return false; } break; case upload: case copy: case synchronize: if (!validate(input.getOptionValue(action.name()))) { return false; } break; } return true; }
From source file:org.ow2.proactive_grid_cloud_portal.cli.CommandSetTest.java
@Test public void testThatArgNamesMatchNumberOfArgs() throws ParseException, IllegalAccessException { int nbArgsBasedOnName = Option.UNINITIALIZED; if (entry.argNames() != null) { String argNames = entry.argNames(); if (entry.hasOptionalArg()) { // argNames description of optional arguments is assumed to start with '[' argNames = argNames.substring(0, argNames.indexOf("[")); }/*from www. j a v a 2 s . co m*/ if (!argNames.trim().isEmpty()) { nbArgsBasedOnName = argNames.split(" ").length; } if (argNames.contains("...")) { nbArgsBasedOnName = Option.UNLIMITED_VALUES; } } Assert.assertEquals("Option '" + entry.longOpt() + "' does not have argNames matching number of args", entry.numOfArgs(), nbArgsBasedOnName); }
From source file:org.uli.util.MyOptionBuilder.java
/** * Resets the member variables to their default values. *//* ww w . j av a2 s.c om*/ private void reset() { description = null; argName = "arg"; longopt = null; type = null; required = false; numberOfArgs = Option.UNINITIALIZED; // PMM 9/6/02 - these were missing optionalArg = false; valuesep = (char) 0; }
From source file:org.uli.util.MyOptionBuilder.java
/** * The next Option created will require an argument value if * <code>hasArg</code> is true. * * @param hasArg if true then the Option has an argument value * @return the OptionBuilder instance/* ww w. ja va 2s. c o m*/ */ public MyOptionBuilder hasArg(boolean hasArg) { this.numberOfArgs = hasArg ? 1 : Option.UNINITIALIZED; return this; }