/** * If this command line has arguments at all. * * @return */ public boolean hasArgs() { return 1 < size(); }
/** * 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); } } }
/** * Resolves the first argument of a command line into either a unique identifier * * @param inputLine * @return */ protected Identifiable findItem(InputLine inputLine) { // first case is one in which this does not apply since there is no argument. if (inputLine.size() <= 1) { return null; } if (inputLine.getLastArg().startsWith("/")) { // then try to process this as a unique identifier. String arg = inputLine.getLastArg().substring(1); Identifier id = BasicIdentifier.newID(arg); return (Identifiable) getStore().get(id); } int choice = inputLine.getIntArg(inputLine.size() - 1); if (allEntries == null || allEntries.isEmpty()) { loadAllEntries(); // just in case... } return allEntries.get(choice); }
/** * Override this to invoke the specific components that make up your CLI. * @param inputLine * @return * @throws Exception */ public boolean use(InputLine inputLine) throws Exception { if (showHelp(inputLine)) { useHelp(); return true; } if (1 == inputLine.size()) { say("Sorry, you need to give the name of the component to invoke it."); return true; } return false; } }
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; }
boolean isInteractive = true; if(1 < inputLine.size()){ publicKeyFile = new File(inputLine.getArg(1));
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"); } } }
if (1 < inputLine.size()) { jsonWebKeys = JSONWebKeyUtil.fromJSON(new File(inputLine.getArg(1))); } else {
return; if (1 == inputLine.size()) {
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 update(InputLine inputLine) { if (showHelp(inputLine)) { showUpdateHelp(); return; } if (inputLine.size() == 1) { say("You must supply the index or id of the item to update"); return; } Identifiable identifiable = findItem(inputLine); if (identifiable != null) { // Note that the contract should be that a clone is passed in and that is saved if the user // decides to. Identifiable identifiable1 = identifiable.clone(); if (update(identifiable1)) { getStore().save(identifiable1); clearEntries(); // CIL-240: Remove entries so the updated item is displayed. } return; } say("no object with that index or id found. Please try again"); }
if (1 == inputLine.size()) {
if (1 < inputLine.size()) { filename = inputLine.getArg(1); } else {