@CLIResolver public RunT getBuildForCLI(@Argument(required=true,metaVar="BUILD#",usage="Build number") String id) throws CmdLineException { try { int n = Integer.parseInt(id); RunT r = getBuildByNumber(n); if (r==null) throw new CmdLineException(null, "No such build '#"+n+"' exists"); return r; } catch (NumberFormatException e) { throw new CmdLineException(null, id+ "is not a number"); } }
/** * Loads the script from the argument. */ private String loadScript() throws CmdLineException, IOException, InterruptedException { if(script==null) throw new CmdLineException(null, "No script is specified"); if (script.equals("=")) return IOUtils.toString(stdin); return checkChannel().call(new ScriptLoader(script)); } }
@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; }
@Override protected int run() throws Exception { Authentication a = Jenkins.getAuthentication(); if (a== Jenkins.ANONYMOUS) throw new CmdLineException("No credentials specified."); // this causes CLI to show the command line options. ClientAuthenticationCache store = new ClientAuthenticationCache(checkChannel()); store.set(a); SecurityListener.fireLoggedIn(a.getName()); return 0; }
/** * Used for CLI binding. */ @CLIResolver public static AbstractProject resolveForCLI( @Argument(required=true,metaVar="NAME",usage="Job name") String name) throws CmdLineException { AbstractProject item = Jenkins.getInstance().getItemByFullName(name, AbstractProject.class); if (item==null) { AbstractProject project = AbstractProject.findNearest(name); throw new CmdLineException(null, project == null ? Messages.AbstractItem_NoSuchJobExistsWithoutSuggestion(name) : Messages.AbstractItem_NoSuchJobExists(name, project.getFullName())); } return item; }
if (pd==null) { String nearest = EditDistance.findNearest(name, pdp.getParameterDefinitionNames()); throw new CmdLineException(null, nearest == null ? String.format("'%s' is not a valid parameter.", name) : String.format("'%s' is not a valid parameter. Did you mean %s?", name, nearest)); throw new CmdLineException(null, String.format("Cannot resolve the value for the parameter '%s'.",name)); throw new CmdLineException(null, String.format("No default value for the parameter '%s'.",pd.getName()));
/** * Used for CLI binding. */ @CLIResolver public static AbstractItem resolveForCLI( @Argument(required=true,metaVar="NAME",usage="Item name") String name) throws CmdLineException { // TODO can this (and its pseudo-override in AbstractProject) share code with GenericItemOptionHandler, used for explicit CLICommand’s rather than CLIMethod’s? AbstractItem item = Jenkins.getInstance().getItemByFullName(name, AbstractItem.class); if (item==null) { AbstractItem project = Items.findNearest(AbstractItem.class, name, Jenkins.getInstance()); throw new CmdLineException(null, project == null ? Messages.AbstractItem_NoSuchJobExistsWithoutSuggestion(name) : Messages.AbstractItem_NoSuchJobExists(name, project.getFullName())); } return item; }
/** * Used for CLI binding. */ @Restricted(DoNotUse.class) @SuppressWarnings("rawtypes") @CLIResolver static ParameterizedJob resolveForCLI(@Argument(required=true, metaVar="NAME", usage="Job name") String name) throws CmdLineException { ParameterizedJob item = Jenkins.getInstance().getItemByFullName(name, ParameterizedJob.class); if (item == null) { ParameterizedJob project = Items.findNearest(ParameterizedJob.class, name, Jenkins.getInstance()); throw new CmdLineException(null, project == null ? hudson.model.Messages.AbstractItem_NoSuchJobExistsWithoutSuggestion(name) : hudson.model.Messages.AbstractItem_NoSuchJobExists(name, project.getFullName())); } return item; }
public String getParameter(int idx) throws CmdLineException { if( pos+idx>=args.length || pos+idx<0 ) throw new CmdLineException(CmdLineParser.this, Messages.MISSING_OPERAND, getOptionName()); return args[pos+idx]; }
@Override protected InetAddress parse(String argument) throws CmdLineException { try { return InetAddress.getByName(argument); } catch (UnknownHostException e) { throw new CmdLineException(owner, Messages.ILLEGAL_IP_ADDRESS, argument); } }
@Override protected Path parse(String argument) throws NumberFormatException, CmdLineException { try { return Paths.get(argument); } catch (Exception e) { throw new CmdLineException(owner, Messages.ILLEGAL_PATH, argument); } }
@Override protected Character parse(String argument) throws NumberFormatException, CmdLineException { if (argument.length() != 1) throw new CmdLineException(owner, Messages.ILLEGAL_CHAR, argument); return argument.charAt(0); } }
@Override protected Character parse(String argument) throws NumberFormatException, CmdLineException { if (argument.length() != 1) throw new CmdLineException(owner, Messages.ILLEGAL_CHAR, argument); return argument.charAt(0); } }
private Boolean getBoolean(String parameter) throws CmdLineException { String valueStr = parameter.toLowerCase(); if (!ACCEPTABLE_VALUES.containsKey(valueStr)) { throw new CmdLineException(owner, Messages.ILLEGAL_BOOLEAN, valueStr); } return ACCEPTABLE_VALUES.get(valueStr); }
@Override protected UUID parse(String argument) throws CmdLineException { try { if (argument.startsWith("{")) argument=argument.substring(1); if (argument.endsWith("}")) argument=argument.substring(0,argument.length()-1); return UUID.fromString(argument); } catch (IllegalArgumentException e) { throw new CmdLineException(owner, Messages.ILLEGAL_UUID, argument); } }
@Override protected UUID parse(String argument) throws CmdLineException { try { if (argument.startsWith("{")) argument=argument.substring(1); if (argument.endsWith("}")) argument=argument.substring(0,argument.length()-1); return UUID.fromString(argument); } catch (IllegalArgumentException e) { throw new CmdLineException(owner, Messages.ILLEGAL_UUID, argument); } }
@Override public int parseArguments(Parameters params) throws CmdLineException { String param = params.getParameter(0); try { setter.addValue(new URI(param)); return 1; } catch (URISyntaxException e) { throw new CmdLineException(owner, Messages.ILLEGAL_OPERAND, params.getParameter(-1), param); } }
@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(Parameters params) throws CmdLineException { String token = params.getParameter(0); try { T value = parse(token); setter.addValue(value); } catch (NumberFormatException ex) { throw new CmdLineException(owner, Messages.ILLEGAL_OPERAND, params.getParameter(-1), token); } return 1; }
@Override public int parseArguments(Parameters params) throws CmdLineException { String token = params.getParameter(0); try { T value = parse(token); setter.addValue(value); } catch (NumberFormatException ex) { throw new CmdLineException(owner, Messages.ILLEGAL_OPERAND, params.getParameter(-1), token); } return 1; }