Oh voices, get out! Get out! Get out! You don’t need to be there telling me what to do and what not to do. Who to do it to etc. You need to go away. Is that too much to ask? I doubt it. But I fear the voices will never go away. They’ll be with me for a long time, and I don’t like that. Do the voices have a purpose in life? I doubt it. I don’t think they have a good purpose with anything. They’re evil voices after all. There isn’t anything good about them! At least I don’t think there is anything good about them. If there were, they wouldn’t be doing all the things now would they? No, I didn’t think so.
I found the code I was looking for:
static class Args {
public static Map<String, List<String>> parseArgs(String[] args, Set<String> validArgs) {
Map<String, List<String>> map = new HashMap<>();
List<String> options = null;
for (String a : args) {
if (a.charAt(0) == '-') {
if (a.length() < 2) {
throw new IllegalArgumentException("Invalid Argument: " + a);
}
if (!validArgs.contains(a)) {
throw new IllegalArgumentException("Invalid Argument: " + a);
}
options = new ArrayList<>();
map.put(a, options);
} else if (options != null) {
options.add(a);
} else {
throw new IllegalArgumentException("Invalid Argument: " + a);
}
}
return map;
}
}
I've modified this piece of code then was in the original post. You can pass this a Set of Strings that ensure only the correct proper argumetns are being passed into the program as to not waste the programs time trying to decide if they are proper later.
Comments
Post a Comment