static void bind(InvocationMatch<?> match, Iterable<ParameterDescriptor> parameters, Object target, Object[] args) throws SyntaxException, InvocationException { for (ParameterDescriptor parameter : parameters) { ParameterMatch parameterMatch = match.getParameter(parameter); Object value = parameterMatch != null ? parameterMatch.computeValue() : null; if (value == null) { if (parameter.getDeclaredType().isPrimitive() || parameter.isRequired()) { if (parameter instanceof ArgumentDescriptor) { ArgumentDescriptor argument = (ArgumentDescriptor)parameter; throw new SyntaxException("Missing argument " + argument.getName()); } else { OptionDescriptor option = (OptionDescriptor)parameter; throw new SyntaxException("Missing option " + option.getNames()); } } } else { ((Binding)parameter).set(target, args, value); } } }
/** * Compute the value from the parameter metadata and the values list. * * @return the invocation value * @throws org.crsh.cli.impl.SyntaxException anything that would prevent the value from being computed */ public Object computeValue() throws SyntaxException { List<String> strings = getStrings(); return parameter.parse(strings); } }
static void bind(InvocationMatch<?> match, Iterable<ParameterDescriptor> parameters, Object target, Object[] args) throws SyntaxException, InvocationException { for (ParameterDescriptor parameter : parameters) { ParameterMatch parameterMatch = match.getParameter(parameter); Object value = parameterMatch != null ? parameterMatch.computeValue() : null; if (value == null) { if (parameter.getDeclaredType().isPrimitive() || parameter.isRequired()) { if (parameter instanceof ArgumentDescriptor) { ArgumentDescriptor argument = (ArgumentDescriptor)parameter; throw new SyntaxException("Missing argument " + argument.getName()); } else { OptionDescriptor option = (OptionDescriptor)parameter; throw new SyntaxException("Missing option " + option.getNames()); } } } else { ((Binding)parameter).set(target, args, value); } } }
/** * Compute the value from the parameter metadata and the values list. * * @return the invocation value * @throws org.crsh.cli.impl.SyntaxException anything that would prevent the value from being computed */ public Object computeValue() throws SyntaxException { List<String> strings = getStrings(); return parameter.parse(strings); } }
void configure(InvocationMatch<T> classMatch, T command) throws InvocationException, SyntaxException { for (ParameterDescriptor parameter : getParameters()) { ParameterMatch match = classMatch.getParameter(parameter); if (match == null) { if (parameter.isRequired()) { if (parameter instanceof ArgumentDescriptor) { ArgumentDescriptor argument = (ArgumentDescriptor)parameter; throw new SyntaxException("Missing argument " + argument.getName()); } else { OptionDescriptor option = (OptionDescriptor)parameter; throw new SyntaxException("Missing option " + option.getNames()); } } } else { Object value = match.computeValue(); Field f = ((ClassFieldBinding)parameter.getBinding()).getField(); try { f.setAccessible(true); f.set(command, value); } catch (Exception e) { throw new InvocationException(e.getMessage(), e); } } } }
/** * Compute the value from the parameter metadata and the values list. * * @return the invocation value * @throws org.crsh.cli.SyntaxException anything that would prevent the value from being computed */ public Object computeValue() throws SyntaxException { List<String> strings = getStrings(); return parameter.parse(strings); } }
ParameterMatch match = _match.getParameter(parameter); if (match != null) { v = match.computeValue(); } else { v = null;