/** * Tells if the token looks like a long option. * * @param token */ private boolean isLongOption(String token) { if (!token.startsWith("-") || token.length() == 1) { return false; } int pos = token.indexOf("="); String t = pos == -1 ? token : token.substring(0, pos); if (!options.getMatchingOptions(t).isEmpty()) { // long or partial long options (--L, -L, --L=V, -L=V, --l, --l=V) return true; } else if (getLongPrefix(token) != null && !token.startsWith("--")) { // -LV return true; } return false; }
@Test public void testGetMatchingOpts() { Options options = new Options(); options.addOption(OptionBuilder.withLongOpt("version").create()); options.addOption(OptionBuilder.withLongOpt("verbose").create()); assertTrue(options.getMatchingOptions("foo").isEmpty()); assertEquals(1, options.getMatchingOptions("version").size()); assertEquals(2, options.getMatchingOptions("ver").size()); } }
/** * Handles the following tokens: * * --L * -L * --l * -l * * @param token the command line token to handle */ private void handleLongOptionWithoutEqual(String token) throws ParseException { List<String> matchingOpts = options.getMatchingOptions(token); if (matchingOpts.isEmpty()) { handleUnknownToken(currentToken); } else if (matchingOpts.size() > 1) { throw new AmbiguousOptionException(token, matchingOpts); } else { handleOption(options.getOption(matchingOpts.get(0))); } }
List<String> matchingOpts = options.getMatchingOptions(opt); if (matchingOpts.isEmpty())
String opt = pos == -1 ? token : token.substring(0, pos); // --foo List<String> matchingOpts = options.getMatchingOptions(opt); else if (!options.getMatchingOptions(token).isEmpty()) List<String> matchingOpts = options.getMatchingOptions(token); if (matchingOpts.size() > 1)
else if (!options.getMatchingOptions(t).isEmpty())
/** * Tells if the token looks like a long option. * * @param token */ private boolean isLongOption(String token) { if (!token.startsWith("-") || token.length() == 1) { return false; } int pos = token.indexOf("="); String t = pos == -1 ? token : token.substring(0, pos); if (!options.getMatchingOptions(t).isEmpty()) { // long or partial long options (--L, -L, --L=V, -L=V, --l, --l=V) return true; } else if (getLongPrefix(token) != null && !token.startsWith("--")) { // -LV return true; } return false; }
/** * Handles the following tokens: * * --L * -L * --l * -l * * @param token the command line token to handle */ private void handleLongOptionWithoutEqual(String token) throws ParseException { List<String> matchingOpts = options.getMatchingOptions(token); if (matchingOpts.isEmpty()) { handleUnknownToken(currentToken); } else if (matchingOpts.size() > 1) { throw new AmbiguousOptionException(token, matchingOpts); } else { handleOption(options.getOption(matchingOpts.get(0))); } }
List<String> matchingOpts = options.getMatchingOptions(opt); if (matchingOpts.isEmpty())
String opt = pos == -1 ? token : token.substring(0, pos); // --foo List<String> matchingOpts = options.getMatchingOptions(opt); else if (!options.getMatchingOptions(token).isEmpty()) List<String> matchingOpts = options.getMatchingOptions(token); if (matchingOpts.size() > 1)
else if (!options.getMatchingOptions(t).isEmpty())