@Override public String[] getPropertyNames() { List<String> names = new ArrayList<>(); for (OptionSpec<?> spec : this.source.specs()) { String lastOption = CollectionUtils.lastElement(spec.options()); if (lastOption != null) { // Only the longest name is used for enumerating names.add(lastOption); } } return StringUtils.toStringArray(names); }
private OptionMetadata findMetadata(OptionSpec<?> option) { List<String> optionNames = option.options(); // TODO: allow lookup of option metadata by name to avoid linear scans... // Though we are dealing with small collection, so shouldn't be too horrible. for (OptionMetadata omd : optionMetadata) { if (optionNames.contains(omd.getName())) { return omd; } } // this was likely a command, not an option. return null; }
@Override public String[] getPropertyNames() { List<String> names = new ArrayList<>(); for (OptionSpec<?> spec : this.source.specs()) { String lastOption = CollectionUtils.lastElement(spec.options()); if (lastOption != null) { // Only the longest name is used for enumerating names.add(lastOption); } } return StringUtils.toStringArray(names); }
private String specToString( OptionSpec<?> option ) { return option.options().stream().collect( joining( "/" ) ); }
private <V> void checkOwnership(OptionSpec<V> option) { if (!(option.options().stream().allMatch(opt -> opt.startsWith(serviceName + ".") || !opt.contains(".")))) { throw new IllegalArgumentException("Cannot process non-arguments"); } } };
private <V> List<V> defaultValueFor( OptionSpec<V> option ) { return defaultValuesFor( option.options().iterator().next() ); } }
private OptionMetadata findMetadata(OptionSpec<?> option) { List<String> optionNames = option.options(); // TODO: allow lookup of option metadata by name to avoid linear scans... // Though we are dealing with small collection, so shouldn't be too horrible. for (OptionMetadata omd : optionMetadata) { if (optionNames.contains(omd.getName())) { return omd; } } // this was likely a command, not an option. return null; }
private <V> List<V> defaultValueFor( OptionSpec<V> option ) { return defaultValuesFor( option.options().iterator().next() ); }
private static Set<String> getOptionNames(OptionsBean bean) { Set<String> names = new HashSet<>(); try { for (Field field : bean.getClass().getDeclaredFields()) { if (OptionSpec.class.isAssignableFrom(field.getType())) { field.setAccessible(true); OptionSpec spec = (OptionSpec) field.get(bean); names.addAll(spec.options()); } } } catch (Exception e) { throw new RuntimeException(e); } return names; }
private static Set<String> getOptionNames(OptionsBean bean) { Set<String> names = new HashSet<>(); try { for (Field field : bean.getClass().getDeclaredFields()) { if (OptionSpec.class.isAssignableFrom(field.getType())) { field.setAccessible(true); OptionSpec spec = (OptionSpec) field.get(bean); names.addAll(spec.options()); } } } catch (Exception e) { throw new RuntimeException(e); } return names; }
private <V> List<V> defaultValueFor( OptionSpec<V> option ) { return defaultValuesFor( option.options().iterator().next() ); } }
private <V> List<V> defaultValueFor( OptionSpec<V> option ) { return defaultValuesFor( option.options().iterator().next() ); } }
private String specToString( OptionSpec<?> option ) { return Strings.join( new ArrayList<>( option.options() ), "/" ); }
private <V> List<V> defaultValueFor( OptionSpec<V> option ) { return defaultValuesFor( option.options().iterator().next() ); }
@Override public String[] getPropertyNames() { List<String> names = new ArrayList<>(); for (OptionSpec<?> spec : this.source.specs()) { String lastOption = CollectionUtils.lastElement(spec.options()); if (lastOption != null) { // Only the longest name is used for enumerating names.add(lastOption); } } return StringUtils.toStringArray(names); }
@Override public String[] getPropertyNames() { List<String> names = new ArrayList<>(); for (OptionSpec<?> spec : this.source.specs()) { String lastOption = CollectionUtils.lastElement(spec.options()); if (lastOption != null) { // Only the longest name is used for enumerating names.add(lastOption); } } return StringUtils.toStringArray(names); }
@Override public String toString() { if (optionSet == null) return ""; String nonOptionArgs = ""; if (optionSet.nonOptionArguments() != null) { int i = 0; for (Object object : optionSet.nonOptionArguments()) { if (i > 0) nonOptionArgs += " "; nonOptionArgs += "\"" + object.toString() + "\""; i++; } } String optionArgs = ""; if (optionSet.asMap() != null) { int i = 0; for (Map.Entry<OptionSpec<?>, List<?>> entry : optionSet.asMap().entrySet()) { if (entry.getValue().size() > 0) { if (i > 0) optionArgs += " "; optionArgs += "--" + entry.getKey().options().get(0) + "=\"" + entry.getValue().get(0) + "\""; i++; } } } return nonOptionArgs + " " + optionArgs; }
/** * Gives the argument associated with the given option. * * <p>This method recognizes only instances of options returned from the fluent interface methods.</p> * * @param <V> represents the type of the arguments the given option accepts * @param option the option to search for * @return the argument of the given option; {@code null} if no argument is present, or that option was not * detected * @throws OptionException if more than one argument was detected for the option * @throws NullPointerException if {@code option} is {@code null} * @throws ClassCastException if the arguments of this option are not of the expected type */ public <V> V valueOf( OptionSpec<V> option ) { ensureNotNull( option ); List<V> values = valuesOf( option ); switch ( values.size() ) { case 0: return null; case 1: return values.get( 0 ); default: throw new MultipleArgumentsForOptionException( option.options() ); } }
/** * Gives the argument associated with the given option. * * <p>This method recognizes only instances of options returned from the fluent interface methods.</p> * * @param <V> represents the type of the arguments the given option accepts * @param option the option to search for * @return the argument of the given option; {@code null} if no argument is present, or that option was not * detected * @throws OptionException if more than one argument was detected for the option * @throws NullPointerException if {@code option} is {@code null} * @throws ClassCastException if the arguments of this option are not of the expected type */ public <V> V valueOf( OptionSpec<V> option ) { ensureNotNull( option ); List<V> values = valuesOf( option ); switch ( values.size() ) { case 0: return null; case 1: return values.get( 0 ); default: throw new MultipleArgumentsForOptionException( option.options() ); } }
/** * Gives the argument associated with the given option. * * <p>This method recognizes only instances of options returned from the fluent interface methods.</p> * * @param <V> represents the type of the arguments the given option accepts * @param option the option to search for * @return the argument of the given option; {@code null} if no argument is present, or that option was not * detected * @throws OptionException if more than one argument was detected for the option * @throws NullPointerException if {@code option} is {@code null} * @throws ClassCastException if the arguments of this option are not of the expected type */ public <V> V valueOf( OptionSpec<V> option ) { ensureNotNull( option ); List<V> values = valuesOf( option ); switch ( values.size() ) { case 0: return null; case 1: return values.get( 0 ); default: throw new MultipleArgumentsForOptionException( option.options() ); } }