in api-reference-examples/java/te-tag-query/com/facebook/threatexchange/TETagQuery.java [1323:1422]
public void handle(
String[] argsAsArray,
int numIDsPerQuery,
boolean verbose,
boolean showURLs,
DescriptorFormatter descriptorFormatter
) {
boolean dryRun = false;
boolean descriptorIDsFromStdin = false;
DescriptorPostParameters postParams = new DescriptorPostParameters();
ArrayList<String> args = new ArrayList<String>(Arrays.asList(argsAsArray));
while (args.size() > 0 && args.get(0).startsWith("-")) {
String option = args.get(0);
args.remove(0);
if (option.equals("-h") || option.equals("--help")) {
usage(0);
} else if (option.equals("--dry-run")) {
dryRun = true;
} else if (option.equals("-N")) {
if (args.size() < 1) {
usage(1);
}
descriptorIDsFromStdin = true;
} else if (option.equals("-n")) {
if (args.size() < 1) {
usage(1);
}
postParams.setDescriptorID(args.get(0));
args.remove(0);
} else if (option.equals("--add-tags")) {
if (args.size() < 1) {
usage(1);
}
postParams.setTagsToAdd(args.get(0));
args.remove(0);
} else if (option.equals("--remove-tags")) {
if (args.size() < 1) {
usage(1);
}
postParams.setTagsToRemove(args.get(0));
args.remove(0);
} else if (option.equals("--tags")) {
if (args.size() < 1) {
usage(1);
}
postParams.setTagsToSet(args.get(0));
args.remove(0);
} else {
boolean handled = this.commonPosterOptionCheck(option, args, postParams);
if (!handled) {
System.err.printf("%s %s: Unrecognized option \"%s\".\n",
PROGNAME, _verb, option);
usage(1);
}
}
}
if (args.size() > 0) {
System.err.printf("%s %s: Extraneous argument \"%s\"\n", PROGNAME, this._verb, args.get(0));
usage(1);
}
if (descriptorIDsFromStdin) {
if (postParams.getDescriptorID() != null) {
System.err.printf("%s %s: exactly one of -N and -n must be supplied.\n",
PROGNAME, _verb);
System.exit(1);
}
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
String line;
int lno = 1;
try {
while ((line = reader.readLine()) != null) {
lno++;
// In Java, line-terminators already stripped for us
postParams.setDescriptorID(line);
updateSingle(postParams, verbose, showURLs, dryRun);
}
} catch (IOException e) {
System.err.printf("Couldn't read line %d of standard input.\n", lno);
System.exit(1);
}
} else {
if (postParams.getDescriptorID() == null) {
System.err.printf("%s %s: exactly one of -N and -n must be supplied.\n",
PROGNAME, _verb);
System.exit(1);
}
updateSingle(postParams, verbose, showURLs, dryRun);
}
}