Refine search
@Override public int parseArguments(Parameters params) throws CmdLineException { String param = params.getParameter(0); Result v = fromString(param.replace('-', '_')); if (v==null) throw new CmdLineException(owner,"No such status '"+param+"'. Did you mean "+ EditDistance.findNearest(param.replace('-', '_').toUpperCase(), getNames())); setter.addValue(v); return 1; }
public MapOptionHandler(CmdLineParser parser, OptionDef option, Setter<? super Map<?,?>> setter) { super(parser, option, setter); if (setter.asFieldSetter()==null) throw new IllegalArgumentException("MapOptionHandler can only work with fields"); }
public SubCommandHandler(CmdLineParser parser, OptionDef option, Setter<Object> setter) { super(parser, option, setter); commands = setter.asAnnotatedElement().getAnnotation(SubCommands.class); if (commands==null) throw new IllegalStateException("SubCommandHandler must be used with @SubCommands annotation"); }
@Override public int parseArguments(Parameters params) throws CmdLineException { String macString = params.getParameter(0); String[] macStringArray = null; throw new CmdLineException(owner, Messages.ILLEGAL_MAC_ADDRESS, macString); setter.asFieldSetter().addValue(mac); return 1;
@Override public int parseArguments(Parameters params) throws CmdLineException { if (params.size() != 1) throw new CmdLineException ("an option of type log level should have one parameter [trace,debug,info,warn,error,fatal,off]"); Level result = Level.toLevel(params.getParameter(0).toLowerCase()); setter.addValue(result); log.debug("set log level " + result); return 1; }
public int parseArguments(Parameters parameters) throws CmdLineException { for (int i=0; i<parameters.size(); i++) setter.addValue(parameters.getParameter(i)); return parameters.size(); }
@Override public int parseArguments(Parameters params) throws CmdLineException { setter.addValue(getView(params.getParameter(0))); return 1; }
@Override public int parseArguments(Parameters params) throws CmdLineException { FieldSetter fs = setter.asFieldSetter(); Map v = (Map)fs.getValue(); if (v==null) { v = createNewCollection(fs.getType()); fs.addValue(v); } addToMap(params.getParameter(0),v); return 1; }
/** * Creates an {@link OptionHandler} that handles the given {@link Option} annotation * and the {@link Setter} instance. */ @SuppressWarnings("unchecked") protected OptionHandler createOptionHandler(CmdLineParser parser, OptionDef o, Setter setter) { checkNonNull(o, "CmdLineParser"); checkNonNull(o, "OptionDef"); checkNonNull(setter, "Setter"); Class<? extends OptionHandler> h = o.handler(); if(h==OptionHandler.class) { // infer the type Class<?> t = setter.getType(); // enum is the special case if(Enum.class.isAssignableFrom(t)) return new EnumOptionHandler(parser,o,setter,t); OptionHandlerFactory factory = handlers.get(t); if (factory==null) throw new IllegalAnnotationError(Messages.UNKNOWN_HANDLER.format(t)); return factory.getHandler(parser, o, setter); } else { // explicit handler specified return new DefaultConstructorHandlerFactory(h).getHandler(parser, o, setter); } }
/** * Programmatically defines an argument (instead of reading it from annotations as normal). * * @param setter the setter for the type * @param a the Argument * @throws NullPointerException if {@code setter} or {@code a} is {@code null}. */ public void addArgument(Setter setter, Argument a) { checkNonNull(setter, "Setter"); checkNonNull(a, "Argument"); OptionHandler h = createOptionHandler(new OptionDef(a,setter.isMultiValued()),setter); int index = a.index(); // make sure the argument will fit in the list while (index >= arguments.size()) { arguments.add(null); } if(arguments.get(index)!=null) { throw new IllegalAnnotationError(Messages.MULTIPLE_USE_OF_ARGUMENT.format(index)); } arguments.set(index, h); }
@Override public int parseArguments(Parameters params) throws CmdLineException { String macString = params.getParameter(0); String[] macStringArray = null; throw new CmdLineException(owner, Messages.ILLEGAL_MAC_ADDRESS, macString); setter.asFieldSetter().addValue(mac); return 1;
public int parseArguments(Parameters parameters) throws CmdLineException { for (int i=0; i<parameters.size(); i++) setter.addValue(parameters.getParameter(i)); return parameters.size(); }
@Override public int parseArguments(Parameters params) throws CmdLineException { String nodeName = params.getParameter(0); final Node node = Jenkins.get().getNode(nodeName); if (node == null) throw new IllegalArgumentException("No such node '" + nodeName + "'"); setter.addValue(node); return 1; }
@Override public int parseArguments(Parameters params) throws CmdLineException { FieldSetter fs = setter.asFieldSetter(); Map v = (Map)fs.getValue(); if (v==null) { v = createNewCollection(fs.getType()); fs.addValue(v); } addToMap(params.getParameter(0),v); return 1; }
/** * Creates an {@link OptionHandler} that handles the given {@link Option} annotation * and the {@link Setter} instance. */ @SuppressWarnings("unchecked") protected OptionHandler createOptionHandler(CmdLineParser parser, OptionDef o, Setter setter) { checkNonNull(o, "CmdLineParser"); checkNonNull(o, "OptionDef"); checkNonNull(setter, "Setter"); Class<? extends OptionHandler> h = o.handler(); if(h==OptionHandler.class) { // infer the type Class<?> t = setter.getType(); // enum is the special case if(Enum.class.isAssignableFrom(t)) return new EnumOptionHandler(parser,o,setter,t); OptionHandlerFactory factory = handlers.get(t); if (factory==null) throw new IllegalAnnotationError(Messages.UNKNOWN_HANDLER.format(t)); return factory.getHandler(parser, o, setter); } else { // explicit handler specified return new DefaultConstructorHandlerFactory(h).getHandler(parser, o, setter); } }
/** * Programmatically defines an argument (instead of reading it from annotations as normal). * * @param setter the setter for the type * @param a the Argument * @throws NullPointerException if {@code setter} or {@code a} is {@code null}. */ public void addArgument(Setter setter, Argument a) { checkNonNull(setter, "Setter"); checkNonNull(a, "Argument"); OptionHandler h = createOptionHandler(new OptionDef(a,setter.isMultiValued()),setter); int index = a.index(); // make sure the argument will fit in the list while (index >= arguments.size()) { arguments.add(null); } if(arguments.get(index)!=null) { throw new IllegalAnnotationError(Messages.MULTIPLE_USE_OF_ARGUMENT.format(index)); } arguments.set(index, h); }
@Override public int parseArguments(Parameters params) throws CmdLineException { String param = params.getParameter(0); try { setter.addValue(new URL(param)); return 1; } catch (MalformedURLException e) { throw new CmdLineException(owner, Messages.ILLEGAL_OPERAND, params.getParameter(-1), param); } }
@Override public int parseArguments (org.kohsuke.args4j.spi.Parameters params) throws CmdLineException { String className = params.getParameter(0).trim(); if (!className.isEmpty()) { try { Class runClass = Class.forName(className); FieldSetter fs = setter.asFieldSetter(); fs.addValue(runClass); } catch (ClassNotFoundException ex) { throw new CmdLineException(owner, ex); } } return 1; } }
@Override public int parseArguments(Parameters params) throws CmdLineException { // end of arg list or next arg is another option if ((params.size() == 0) || params.getParameter(0).startsWith("-")) { setter.addValue(TRUE); return 0; } else { setter.addValue(getBoolean(params.getParameter(0))); return 1; } }
@Override public int parseArguments(Parameters params) throws CmdLineException { final Jenkins j = Jenkins.get(); final String src = params.getParameter(0); T s = j.getItemByFullName(src, type()); if (s == null) { final Authentication who = Jenkins.getAuthentication(); try (ACLContext acl = ACL.as(ACL.SYSTEM)) { Item actual = j.getItemByFullName(src); if (actual == null) { LOGGER.log(Level.FINE, "really no item exists named {0}", src); } else { LOGGER.log(Level.WARNING, "running as {0} could not find {1} of {2}", new Object[] {who.getPrincipal(), actual, type()}); } } T nearest = Items.findNearest(type(), src, j); if (nearest != null) { throw new IllegalArgumentException("No such job '" + src + "'; perhaps you meant '" + nearest.getFullName() + "'?"); } else { throw new IllegalArgumentException("No such job '" + src + "'"); } } setter.addValue(s); return 1; }