in sdk/src/main/java/com/google/cloud/dataflow/sdk/options/PipelineOptionsFactory.java [315:369]
static boolean printHelpUsageAndExitIfNeeded(ListMultimap<String, String> options,
PrintStream printStream, boolean exit) {
if (options.containsKey("help")) {
final String helpOption = Iterables.getOnlyElement(options.get("help"));
// Print the generic help if only --help was specified.
if (Boolean.TRUE.toString().equals(helpOption)) {
printHelp(printStream);
if (exit) {
System.exit(0);
} else {
return true;
}
}
// Otherwise attempt to print the specific help option.
try {
Class<?> klass = Class.forName(helpOption);
if (!PipelineOptions.class.isAssignableFrom(klass)) {
throw new ClassNotFoundException("PipelineOptions of type " + klass + " not found.");
}
printHelp(printStream, (Class<? extends PipelineOptions>) klass);
} catch (ClassNotFoundException e) {
// If we didn't find an exact match, look for any that match the class name.
Iterable<Class<? extends PipelineOptions>> matches = Iterables.filter(
getRegisteredOptions(),
new Predicate<Class<? extends PipelineOptions>>() {
@Override
public boolean apply(Class<? extends PipelineOptions> input) {
if (helpOption.contains(".")) {
return input.getName().endsWith(helpOption);
} else {
return input.getSimpleName().equals(helpOption);
}
}
});
try {
printHelp(printStream, Iterables.getOnlyElement(matches));
} catch (NoSuchElementException exception) {
printStream.format("Unable to find option %s.%n", helpOption);
printHelp(printStream);
} catch (IllegalArgumentException exception) {
printStream.format("Multiple matches found for %s: %s.%n", helpOption,
Iterables.transform(matches, ReflectHelpers.CLASS_NAME));
printHelp(printStream);
}
}
if (exit) {
System.exit(0);
} else {
return true;
}
}
return false;
}