in api-reference-examples/java/te-tag-query/com/facebook/threatexchange/TETagQuery.java [1159:1246]
public void handle(
String[] argsAsArray,
int numIDsPerQuery,
boolean verbose,
boolean showURLs,
DescriptorFormatter descriptorFormatter
) {
boolean dryRun = false;
boolean indicatorTextFromStdin = 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("-I")) {
indicatorTextFromStdin = true;
} else if (option.equals("-i") || option.equals("--indicator")) {
if (args.size() < 1) {
usage(1);
}
postParams.setIndicatorText(args.get(0));
args.remove(0);
} else if (option.equals("-t") || option.equals("--type")) {
if (args.size() < 1) {
usage(1);
}
postParams.setIndicatorType(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 (indicatorTextFromStdin) {
if (postParams.getIndicatorText() != null) {
System.err.printf("%s %s: exactly one of -I and -i 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.setIndicatorText(line);
submitSingle(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.getIndicatorText() == null) {
System.err.printf("%s %s: exactly one of -I and -i must be supplied.\n",
PROGNAME, _verb);
System.exit(1);
}
submitSingle(postParams, verbose, showURLs, dryRun);
}
}