private boolean hasOptionWithLongName(String name) { for (Option option : cli.getOptions()) { if (name.equalsIgnoreCase(option.getLongName())) { return true; } } return false; }
@Override public CLI removeOption(String name) { options = options.stream().filter(o -> !o.getLongName().equals(name) && !o.getShortName().equals(name)) .collect(Collectors.toList()); return this; }
/** * Returns the options with a long name starting with the name specified. * * @param opt the partial name of the option * @return the options matching the partial name specified, or an empty list if none matches */ public List<Option> getMatchingOptions(String opt) { opt = stripLeadingHyphens(opt); List<Option> matching = new ArrayList<>(); final List<Option> options = cli.getOptions(); // Exact match first for (Option option : options) { if (opt.equalsIgnoreCase(option.getLongName())) { return Collections.singletonList(option); } } for (Option option : options) { if (option.getLongName() != null && option.getLongName().startsWith(opt)) { matching.add(option); } } return matching; }
@Override public Option getOption(String name) { Objects.requireNonNull(name); // The option by name look up is a three steps lookup: // first check by long name // then by short name // finally by arg name for (Option option : options) { if (name.equalsIgnoreCase(option.getLongName())) { return option; } } for (Option option : options) { if (name.equalsIgnoreCase(option.getShortName())) { return option; } } for (Option option : options) { if (name.equalsIgnoreCase(option.getArgName())) { return option; } } return null; }
/** * Retrieve the {@link Option} matching the long or short name specified. * The leading hyphens in the name are ignored (up to 2). * * @param opt short or long name of the {@link Option} * @return the option represented by opt */ public Option getOption(String opt) { opt = stripLeadingHyphens(opt); for (Option option : cli.getOptions()) { if (opt.equalsIgnoreCase(option.getShortName()) || opt.equalsIgnoreCase(option.getLongName())) { return option; } } return null; }
private Option find(List<Option> options, String name) { final List<Option> match = options.stream().filter(c -> c.getLongName().equalsIgnoreCase(name)) .collect(Collectors.toList()); if (match.isEmpty()) { fail("Cannot find option '" + name + "' in " + options.stream().map(Option::getLongName) .collect(Collectors.toList())); } return match.get(0); }
buf.append(lpad).append(" ").append(getLongOptionPrefix()).append(option.getLongName()); } else { buf.append(lpad).append(getOptionPrefix()).append(option.getShortName()); if (!isNullOrEmpty(option.getLongName())) { buf.append(',').append(getLongOptionPrefix()).append(option.getLongName()); buf.append(!isNullOrEmpty(option.getLongName()) ? longOptSeparator : " "); buf.append(option.getChoices().stream().collect(Collectors.joining(", ", "{", "}"))); } else if (option.acceptValue()) { buf.append(!isNullOrEmpty(option.getLongName()) ? longOptSeparator : " "); buf.append("<").append(argName != null ? option.getArgName() : getArgName()).append(">");
json.put("help", obj.isHelp()); json.put("hidden", obj.isHidden()); if (obj.getLongName() != null) { json.put("longName", obj.getLongName());
buff.append("-").append(option.getShortName()); } else { buff.append("--").append(option.getLongName());
private boolean hasOptionWithLongName(String name) { for (Option option : cli.getOptions()) { if (name.equalsIgnoreCase(option.getLongName())) { return true; } } return false; }
@Override public CLI removeOption(String name) { options = options.stream().filter(o -> !o.getLongName().equals(name) && !o.getShortName().equals(name)) .collect(Collectors.toList()); return this; }
/** * Returns the options with a long name starting with the name specified. * * @param opt the partial name of the option * @return the options matching the partial name specified, or an empty list if none matches */ public List<Option> getMatchingOptions(String opt) { opt = stripLeadingHyphens(opt); List<Option> matching = new ArrayList<>(); final List<Option> options = cli.getOptions(); // Exact match first for (Option option : options) { if (opt.equalsIgnoreCase(option.getLongName())) { return Collections.singletonList(option); } } for (Option option : options) { if (option.getLongName() != null && option.getLongName().startsWith(opt)) { matching.add(option); } } return matching; }
@Override public Option getOption(String name) { Objects.requireNonNull(name); // The option by name look up is a three steps lookup: // first check by long name // then by short name // finally by arg name for (Option option : options) { if (name.equalsIgnoreCase(option.getLongName())) { return option; } } for (Option option : options) { if (name.equalsIgnoreCase(option.getShortName())) { return option; } } for (Option option : options) { if (name.equalsIgnoreCase(option.getArgName())) { return option; } } return null; }
/** * Retrieve the {@link Option} matching the long or short name specified. * The leading hyphens in the name are ignored (up to 2). * * @param opt short or long name of the {@link Option} * @return the option represented by opt */ public Option getOption(String opt) { opt = stripLeadingHyphens(opt); for (Option option : cli.getOptions()) { if (opt.equalsIgnoreCase(option.getShortName()) || opt.equalsIgnoreCase(option.getLongName())) { return option; } } return null; }
private Option find(List<Option> options, String name) { final List<Option> match = options.stream().filter(c -> c.getLongName().equalsIgnoreCase(name)) .collect(Collectors.toList()); if (match.isEmpty()) { fail("Cannot find option '" + name + "' in " + options.stream().map(Option::getLongName) .collect(Collectors.toList())); } return match.get(0); }
buf.append(lpad).append(" ").append(getLongOptionPrefix()).append(option.getLongName()); } else { buf.append(lpad).append(getOptionPrefix()).append(option.getShortName()); if (!isNullOrEmpty(option.getLongName())) { buf.append(',').append(getLongOptionPrefix()).append(option.getLongName()); buf.append(!isNullOrEmpty(option.getLongName()) ? longOptSeparator : " "); buf.append(option.getChoices().stream().collect(Collectors.joining(", ", "{", "}"))); } else if (option.acceptValue()) { buf.append(!isNullOrEmpty(option.getLongName()) ? longOptSeparator : " "); buf.append("<").append(argName != null ? option.getArgName() : getArgName()).append(">");
json.put("help", obj.isHelp()); json.put("hidden", obj.isHidden()); if (obj.getLongName() != null) { json.put("longName", obj.getLongName());
assertEquals(copy.isHelp(), option.isHelp()); assertEquals(copy.isHidden(), option.isHidden()); assertEquals(copy.getLongName(), option.getLongName()); assertEquals(copy.isMultiValued(), option.isMultiValued()); assertEquals(copy.isRequired(), option.isRequired()); assertEquals(copy.isHelp(), option.isHelp()); assertEquals(copy.isHidden(), option.isHidden()); assertEquals(copy.getLongName(), option.getLongName()); assertEquals(copy.isMultiValued(), option.isMultiValued()); assertEquals(copy.isRequired(), option.isRequired());
buff.append("-").append(option.getShortName()); } else { buff.append("--").append(option.getLongName());
assertEquals(copy.isHelp(), option.isHelp()); assertEquals(copy.isHidden(), option.isHidden()); assertEquals(copy.getLongName(), option.getLongName()); assertEquals(copy.isMultiValued(), option.isMultiValued()); assertEquals(copy.isRequired(), option.isRequired()); assertEquals(copy.isHelp(), option.isHelp()); assertEquals(copy.isHidden(), option.isHidden()); assertEquals(copy.getLongName(), option.getLongName()); assertEquals(copy.isMultiValued(), option.isMultiValued()); assertEquals(copy.isRequired(), option.isRequired());