private void invalidNamedArgument(String[] args) throws ArgumentDoesNotExistException { for (int i = 0; i < args.length; i++) { if (args[i].startsWith("--")) { String[] splitLongNamedArg = new String[2]; splitLongNamedArg = args[i].split("--"); NamedArgument tempArg = getNamedArgument(splitLongNamedArg[1]); if (tempArg == null) { invalidNamedArgument = splitLongNamedArg[1]; throw new ArgumentDoesNotExistException( argumentDoesNotExistMessage(invalidNamedArgument)); } } else if (args[i].startsWith("-")) { String[] splitShortNamedArg = new String[2]; splitShortNamedArg = args[i].split("-"); if (splitShortNamedArg[1].length() == 1) { // single char NamedArgument tempArg = getNamedArgument(splitShortNamedArg[1].charAt(0)); if (tempArg == null) { invalidNamedArgument = splitShortNamedArg[1]; throw new ArgumentDoesNotExistException( argumentDoesNotExistMessage(invalidNamedArgument)); } } else { for (int k = 0; k < splitShortNamedArg[1].length(); k++) { NamedArgument tempArg = getNamedArgument(splitShortNamedArg[1].charAt(k)); if (tempArg == null) { invalidNamedArgument = Character.toString(splitShortNamedArg[1].charAt(k)); throw new ArgumentDoesNotExistException( argumentDoesNotExistMessage(invalidNamedArgument)); } } } } } }
private ArrayList<String> getPositionalArgs(String[] args) { ArrayList<String> posArgList = new ArrayList<String>(); for (int i = 0; i < args.length; i++) { // going through args from CLI if (!args[i].startsWith("-") && i == 0) { // test if the first arg is a positional arg posArgList.add(args[i]); } else if (!args[i].startsWith("-")) { // arg from CLI doesn't have a dash if (!args[i - 1].startsWith( "-")) { // if the one before it doesn't have a dash, then it's a pos arg posArgList.add(args[i]); } else { String[] tempNamedArg = new String[2]; if (args[i - 1].startsWith("--")) { tempNamedArg = args[i - 1].split("--"); for (int j = 0; j < namedArgumentList.size(); j++) { // g NamedArgument currentNamedArg = namedArgumentList.get(j); if (currentNamedArg.getName().equals(tempNamedArg[1])) { if (currentNamedArg.getType().equals("boolean")) { // to pos args posArgList.add(args[i]); } } } } else { tempNamedArg = args[i - 1].split("-"); if (tempNamedArg[1].length() == 1) { for (int j = 0; j < namedArgumentList.size(); j++) { NamedArgument currentNamedArg = namedArgumentList.get(j); if (Character.toString(currentNamedArg.getShortFormName()) .equals(tempNamedArg[1])) { if (currentNamedArg.getType().equals("boolean")) { posArgList.add(args[i]); } } } } else { posArgList.add(args[i]); } } } } } return posArgList; }
private void setShortFormNamedArgValues(String[] args) throws NumberFormatException { for (int i = 0; i < args.length; i++) { String[] tempNamedArg = new String[2]; if (args[i].startsWith("-")) { tempNamedArg = args[i].split("-"); for (int k = 0; k < namedArgumentList.size(); k++) { incorrectDataTypeIndex = k; incorrectArgumentType = "named"; NamedArgument currentNamedArg = namedArgumentList.get(k); if (tempNamedArg[1].length() == 1) { // single char if (Character.toString(currentNamedArg.getShortFormName()).equals(tempNamedArg[1])) { if (!currentNamedArg.getType().equals("boolean")) { incorrectArgValueForSpecifiedDataType = args[i + 1]; if (currentNamedArg.getType().equals("integer")) { int argValue = Integer.parseInt(args[i + 1]); currentNamedArg.setValue(args[i + 1]); } else if (currentNamedArg.getType().equals("float")) { float argValue = Float.parseFloat(args[i + 1]); currentNamedArg.setValue(args[i + 1]); } else if (currentNamedArg.getType().equals("string")) { currentNamedArg.setValue(args[i + 1]); } } else { currentNamedArg.setValue("true"); } } } else { // multiple flags in one specification for (int j = 0; j < tempNamedArg[1].length(); j++) { if (currentNamedArg.getShortFormName() == tempNamedArg[1].charAt(j)) { currentNamedArg.setValue("true"); } } } } } } }