/** * This will find the index for the "key" and return the very next argument. This is a * very, very use idiom for retrieving arguments for options.<br/><br/> * E.g. If the command line were * <pre> * myfunc -x foo -y fnord -blarg * </pre> * Then * <pre> * getNextArgFor("-x"); * </pre> * would return "foo". On the other hand * <pre> * getNextArgFor("-blarg"); * </pre> * would return a null, since there is no possible argument for it. * * @param key * @return */ public String getNextArgFor(String key){ int index = indexOf(key); // NOTE that the indexOf command starts at 1, since the zeroth index is always omitted if(index ==getArgs().size()){ // so it is the last arg in the string and there cannot be another return null; } return getArg(1 + index); // finally, a result! } }
/** * returns "true if the command has the flag --help in it. This is a cue from the user to show * the help for a given function. So it the function is called "X" and its help is in the function * "showXHelp" then a value of true from this should simply invoke "showXHelp" and return. * * @param inputLine * @return */ protected boolean showHelp(InputLine inputLine) { if ((1 < inputLine.size()) && inputLine.getArg(1).equals("--help")) return true; return false; }
/** * returns "true if the command has the flag --help in it. This is a cue from the user to show * the help for a given function. So it the function is called "X" and its help is in the function * "showXHelp" then a value of true from this should simply invoke "showXHelp" and return. * * @param inputLine * @return */ protected boolean showHelp(InputLine inputLine) { if ((1 < inputLine.size()) && inputLine.getArg(1).equals("--help")) return true; return false; }
/** * returns "true if the command has the flag --help in it. This is a cue from the user to show * the help for a given function. So it the function is called "X" and its help is in the function * "showXHelp" then a value of true from this should simply invoke "showXHelp" and return. * * @param inputLine * @return */ protected boolean showHelp(InputLine inputLine) { if ((1 < inputLine.size()) && inputLine.getArg(1).equals("--help")) return true; return false; }
/** * This will take an input line and search for the arg, returning the next value. * E.g. if the input line is "-file y -id z -v" * then supplying "-file" as the key here will return "y". * If there is no such key, then a null is returned. * * @param inputLine * @param key * @return */ protected String getArgValue(InputLine inputLine, String key) { int index = inputLine.indexOf(key); if (index == -1) return null; // Remember that the input line has the name of the method as the zeroth argument, so // it is always at least 1 in length if (inputLine.size() + 1 == index) { //then this is the final argument and nothing follows return null; } return inputLine.getArg(index + 1); }
public void setgrant(InputLine inputLine) throws Exception { if (inputLine.size() != 2 || showHelp(inputLine)) { setGrantHelp(); return; } String x = inputLine.getArg(1); // zero-th element is the name of this function. 1st is the actual argument. // now we parse this. if (!x.startsWith(getCe().getCallback().toString())) { say("The callback in the configuration does not match that in the argument you gave"); return; } String args = x.substring(x.indexOf("?") + 1); // skip the ? in the substring. StringTokenizer st = new StringTokenizer(args, "&"); while (st.hasMoreTokens()) { String current = st.nextToken(); if (current.startsWith("code=")) { URI uri = URI.create(decode(current.substring(5))); say("grant=" + uri.toString()); // length of string "code=" grant = new AuthorizationGrantImpl(uri); } } }
public String getLastArg(){ if(size() == 0){ throw new ArgumentNotFoundException(); } return getArg(size() - 1); }
public void create_hash(InputLine inputLine) { if (showHelp(inputLine)) { showCreateHashHelp(); return; } String secret = null; if (inputLine.hasArg("-file")) { try { FileReader fis = new FileReader(inputLine.getArg(1 + inputLine.indexOf("-file"))); StringBuffer sb = new StringBuffer(); int i; while ((i = fis.read()) != -1) { sb.append((char) i); } fis.close(); secret = sb.toString(); } catch (Throwable t) { say("Error: could not read file: " + t.getMessage()); return; } } else { secret = inputLine.getLastArg(); } say("creating hash of " + secret); say(DigestUtils.sha1Hex(secret)); }
/** * If the state supports this, it will save the current cert to a file. The complete filename must be supplied, * including any path. * * @param inputLine * @throws Exception */ public void savecert(InputLine inputLine) throws Exception { if (showHelp(inputLine)) { saveCertHelp(); return; } if (assetResponse == null) { say("Sorry, but there is no cert to save. Please do a successful getcert call first."); return; } String cert = CertUtil.toPEM(assetResponse.getX509Certificates()); if (!inputLine.hasArgs()) { say("Sorry. You did not specify a file so the cert cannot be saved."); return; } String fileName = inputLine.getArg(1); FileWriter fileWriter = new FileWriter(fileName); BufferedWriter bufferedWriter = new BufferedWriter(fileWriter); bufferedWriter.write(cert + "\n"); bufferedWriter.flush(); bufferedWriter.close(); say("File \"" + fileName + "\" saved successfully."); }
public void load(InputLine inputLine) throws Exception { if (showHelp(inputLine)) { showLoadHelp(); return; } String fileName = null; String configName = inputLine.getArg(1); if (2 < inputLine.size()) { fileName = inputLine.getArg(2); } else { fileName = getConfigFile(); } say("loading configuration from " + fileName + ", named " + configName); info("loading configuration from " + fileName + ", named " + configName); loadConfig(fileName, configName); say("done!"); }
public void set_default_id(InputLine inputLine) throws Exception { if (showHelp(inputLine)) { createTokenHelp(); return; } if (1 < inputLine.size()) { defaultKeyID = inputLine.getArg(1); return; } String x = getInput("Enter the key id"); // do nothing if there is no value supplied. if (isEmpty(x)) { return; } defaultKeyID = x; }
return; String source = inputLine.getArg(1); String target = inputLine.getArg(2); boolean verify = false; if (inputLine.size() == 4) { verify = inputLine.getArg(3).equals(VERIFY_OPTION); "-" + CopyTool.SOURCE_CONFIG_NAME_OPTION, inputLine.getArg(1), "-" + CopyTool.TARGET_CONFIG_NAME_OPTION, inputLine.getArg(2), "-" + CopyTool.VERBOSE_OPTION}; //make sure it talks to the user. getCopyTool().run(args);
public void validate_token(InputLine inputLine) throws Exception { if (showHelp(inputLine)) { printValidateTokenHelp(); return; } String token = null; if (1 == inputLine.size()) { say("Sorry, no argument"); return; } if (inputLine.hasArg("-file")) { token = getArgValue(inputLine, "-file"); } else { token = inputLine.getArg(1); } String[] x = decat(token); JSONObject h = JSONObject.fromObject(new String(Base64.decodeBase64(x[0]))); JSONObject p = JSONObject.fromObject(new String(Base64.decodeBase64(x[1]))); say("header=" + h); say("payload=" + p); if (JWTUtil.verify(h, p, x[2], keys.get(defaultKeyID))) { say("token valid!"); } else { say("could not validate token"); } } }
jsonWebKeys = JSONWebKeyUtil.fromJSON(new File(inputLine.getArg(1))); } else { if (keys == null) {
hasFile = true; } catch (FileNotFoundException e) { say("warning, could not find file at path " + inputLine.getArg(inputLine.indexOf("-file")));
filename = inputLine.getArg(1); } else { filename = getInput("Enter full path to the claims file.");
id = BasicIdentifier.newID(inputLine.getArg(1)); if (getStore().containsKey(id)) { throw new IllegalArgumentException("Error: The identifier \"" + id + "\" already has an entry in this store.");